Search code examples
javaspringthymeleaf

Thymeleaf spring loop n item


I am quite new to spring framework.

I try to iterate 10 item in a list. I use thymeleaf template.

This is my code for ;

<li th:each="item,iter : ${list}">
        <span th:if="${iter.index} <=10  " th:text="${item}"/>
</li>

This code is not working and I could not find a way to run the code.

Thanks for your interest.


Solution

  • To iterate 10 items in a list. You should:

     <li th:each="item, index : ${yourList}" th:unless="${index.index > 10}"></li>
    

    This code works. Send me a comment if it doesn't fit for you.