Reputation: 75237
I make a search and get response from server with Thymeleaf. This holds the number of results:
${response.count}
I want to make an iteration like that:
for (int i = 1; i <= response.count; i++) {
if (response.page == i) {
<button class="active">Dummy</button>
} else {
<button>Dummy</button>
}
}
How can I do that? I've tried something like that:
${#numbers.sequence(0, response.count)}
but didn't work.
EDIT: I've tried that but didn't work too:
<button th:each="i: ${#numbers.sequence(0, response.count - 1)}" th:class="${i == response.page} ?: active">Dummy</button>
Upvotes: 18
Views: 24759
Reputation: 20487
This works for me:
<th:block th:each="i: ${#numbers.sequence(0, response.count - 1)}">
<button th:if="${response.page == i}" class="active">Dummy</button>
<button th:unless="${response.page == i}">Dummy</button>
</th:block>
Upvotes: 36