Using Iteration variable in thymeleaf

Viewed 8495

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 ??

2 Answers

Just in case your div already has a class and you want to append a new class, use th:classappend:

<div class="col-md-12" th:each="propName,iterStat : ${propNames}" th:classappend="${iterStat.odd}? 'odd' : 'even'">
...

Related