Injecting a set of files in a Thymeleaf template while keeping the amount of tags at a minimum
Thymeleaf has a mechanism for removing template fragments. You can use the th:remove="tag" attribute to remove the containing tag but not its children:

&lt;div th:each="f : ${files}" th:remove="tag"&gt;
    &lt;h1 th:text="${f.value.pageTitle}"&gt;&lt;/h1&gt;
    [(${content[ f.key ]})]
&lt;/div&gt;


The resulting output will not contain the div but the h1 element and the text node.