Thymeleaf – How to loop a list by index

Thymeleaf th:each allows you to declare an iteration status variable

<span th:each="task,iter : ${foo.tasks}">

Then in the loop you can refer to iter.index and iter.size.

See Tutorial: Using Thymeleaf – 6.2 Keeping iteration status.

Leave a Comment