Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Iteration variable in thymeleaf

Hi I am new to thymeleaf and am converting ma old project from jsp to thymeleaf.I am trying to convert a piece of code written in jsp which is :

<logic:iterate id="someForm" name="formName" property="nameList" indexId="i">
<%if (i%2==0)
{
 className="even";
 }
 else
 {
  className="odd";
 }
 %>
//some code here

can anyone help me with converting this code in thymeleaf ??

like image 510
Deepak Ramakrishnan Kalidass Avatar asked Dec 12 '22 08:12

Deepak Ramakrishnan Kalidass


1 Answers

What you're looking for is in the Thymeleaf documentation. Assuming you need to iterate over your collection to display div tags:

<div th:each="propName,iterStat : ${propNames}" th:class="${iterStat.odd}? 'odd' : 'even'">
    ...
</div
like image 63
tduchateau Avatar answered Dec 25 '22 06:12

tduchateau