Reputation: 107
I am trying to use Thymeleaf if
and unless
but it is not working. What I am trying to do is I want to check if the statusNm
variable has a value of 'Approved' then it will display the content otherwise it will leave it blank.
But I am not able to achieve it. Please suggest me a solution.
<th>Approved Date</th>
<td th:if="${obj.statusNm}=='Approved'" th:text="${obj.modifyDt}"></td>
<td th:unless="${obj.statusNm}" th:text=""></td>
<th>Approved By</th>
<td th:if="${obj.statusNm}=='Approved'" th:text="${obj.modifier}"></td>
<td th:unless="${obj.statusNm}" th:text=""></td>
Upvotes: 0
Views: 247
Reputation: 6912
As the alternative, you may look at Conditional expressions and evaluate your condition directly in th:text
attribute ...
<th>Approved Date</th>
<td th:text="${obj.statusNm=='Approved'} ? ${obj.modifyDt}"></td>
<th>Approved By</th>
<td th:text="${obj.statusNm=='Approved'} ? ${obj.modifier}"></td>
Upvotes: 1
Reputation: 26858
The equals check must be inside the curly brackets like this:
<th>Approved Date</th>
<td th:if="${obj.statusNm=='Approved'}" th:text="${obj.modifyDt}"></td>
<td th:unless="${obj.statusNm=='Approved'}" th:text=""></td>
Upvotes: 1