Stelium
Stelium

Reputation: 1367

Thymeleaf conditions with iterator

I have come across this ability of thymeleaf which based on the iterator I can specify the class of the dom element.

<tr th:each="item,iter : ${items}" th:class="${iter.odd} ? 'info' : '' " >

However, I want to do that on a specific row (let's say the 5th) and none of these statements work

 <tr th:each="item,iter : ${items}" th:class="${iter == 5} ? 'info' : '' " >
 <tr th:each="item,iter : ${items}" th:class="${iter} == 5 ? 'info' : '' " >

Is this not the appropriate syntax?

Upvotes: 0

Views: 175

Answers (1)

Metroids
Metroids

Reputation: 20487

The iter variable is called the status variable and it isn't an integer (which is why you can't compare it to 5, like you're trying to do). Rather it's an object with properties you can use.

In this case, you should use the count property, like this:

 <tr th:each="item,iter : ${items}" th:class="${iter.count == 5} ? 'info' : ''" >

Upvotes: 1

Related Questions