I want to loop through 1 to 5 in the thymeleaf, similar to jsp code:
<c: forEach begin = "1" end = "5" varStatus = "V"> </ c: forEach>.
In Thymeleaf, iteration is achieved by using the th:each attribute. One of the interesting things about this attribute is that it will accept and iterate over some different data types, such as: objects implementing java. util.
The best solution would be the put this logic in the controller and put the first product of type 'T' in a separate attribute. If that's not possible, another solution would be to write a Thymeleaf extension (or if using Spring a bean) that does this.
th:block is a Thymeleaf element rather than an attribute, and it has the general syntax: 1 2 3. <th:block> <!-- Your HTML code --> </th:block> th:block allows you to apply the same Thymeleaf attribute, like th:if or th:each to a block of code.
<th:block th:each="i: ${#numbers.sequence(1, 5)}"></th:block>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With