krenkz
krenkz

Reputation: 470

How to dynamically add a variable to ternary operator in thymeleaf

I am trying to pass a variable from my spring boot controller to a heading with a ternary operator and nothing seems to work.

<h1 th:text="${createEntry} ? 'Create a new Entry:' : 'Edit Entry no. ${id}'"/></h1>

returns

Edit Entry no. ${id}

What is the correct syntax?

Upvotes: 0

Views: 1274

Answers (1)

Metroids
Metroids

Reputation: 20487

<h1 th:text=${createEntry ? 'Create a new Entry:' : 'Edit Entry no. ' + id}" />

or

<h1 th:text="${createEntry} ? 'Create a new Entry:' : 'Edit Entry no. ' + ${id}"/>

Upvotes: 2

Related Questions