ovod
ovod

Reputation: 1178

insert html code using Thymeleaf

I have the list products. I want to create condition when this list is empty - just add plain text to my page, but if not - want to iterate over it and add like table. What I have for the moment is:

<span th:if="${#lists.isEmpty(projects)}" th:text="No projects for chosen category." th:remove="tag"/>
<span th:unless="${#lists.isEmpty(projects)}" th:utext="${<table><td>ID:</td><td>Example text</td></table>}" th:remove="tag"/>

The problem here is how can I conditionally add table to my page with iterating over it using Thymeleaf?

Upvotes: 0

Views: 423

Answers (1)

ovod
ovod

Reputation: 1178

At last I have found solution. There is no need to add html tags using th:text. It is better and simpler just use conditions like this:

<table th:if="condition" th:each="iterating expression"></table>

This will say that add only when condition is true and iterate over whatever you want. Cool approach)

Upvotes: 1

Related Questions