0

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?

1 Answer 1

1

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)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.