The Thymeleaf 2.1.4 white paper demonstrates the use of for each , as shown below:
<tr th:each="prod : ${prods}" th:class="${prodStat.odd}? 'odd'"> <td th:text="${prod.name}">Onions</td> <td th:text="${prod.price}">2.41</td> ... </tr>
It generates one <tr> at each iteration, which is ideal in this situation. However, in my case, I do not need an external tag (here <tr> ).
My use case is to generate the <bookmark> recursive way, other tags do not include, and the <bookmark> should contain the name and href attribute.
<!DOCTYPE html SYSTEM "http://www.thymeleaf.org/dtd/xhtml1-strict-thymeleaf-4.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org"> <body> <div th:fragment="locationBookmark(location)"> <bookmark th:each="map : ${location.subMaps}"> <bookmark th:name="${map.name}" th:href="'#'+${map.id}" th:include=":: locationBookmark(${map})"> </bookmark> </bookmark> </div> </body> </html>
switching side:
<bookmark th:include="bookmark : locationBookmark(${rootLocation})"/>
Many thanks.
java template-engine thymeleaf
July
source share