Marged
Marged

Reputation: 10953

Conditional expressions in Thymeleaf text template

Somehow I don't grasp the concepts behind thymeleaf text template syntax. From my html templates I know code like this:

<div th:if="${#lists.isEmpty(foreign)}">
<div th:unless="${#lists.isEmpty(foreign)}">

I learnt that ${variable} needs to be rewritten to [(${variable})] because otherwise it will not be recognized and thus not replaced. But how do I need to write if and other conditional expressions ? Looking at the docs didn't help me much.

Upvotes: 2

Views: 744

Answers (1)

Marged
Marged

Reputation: 10953

I'm providing this answer to my own question because I think that others might have the same problem finding the correct link. The information I was searching for is available at https://www.thymeleaf.org/doc/articles/thymeleaf3migration.html in chapter 4.1.

For me this boils down to a template that looks like this:

[# th:unless="@{#lists.isEmpty(foo1list)}"]
  OR Foo1 IS IN ( @{foo1List} )
[/]
[# th:unless="@{#lists.isEmpty(foo2list)}"]
  OR Foo2 IS IN ( @{foo2List} )
[/]
[# th:unless="@{#lists.isEmpty(foo3list)}"]
  OR Foo3 IS IN ( @{foo3List} )
[/]

After I had found this syntax in the migration guide I was able to identify this as the proper section in the big documentation file.

Upvotes: 3

Related Questions