Durga
Durga

Reputation: 565

How to apply if condition in table td in thymeleaf

I am new to thymeleaf, I have a little problem. I am successfully getting data from database and displaying to table formate, here i am getting true/false from database. Same thing displaying in table formate.

But i want to show true as yes and fasle as no in front end.

<tbody>
<tr th:each="trn,iterStat : ${trans}">  
<td th:text="${trn.txn}">Yes</td>
</tr>
</tbody>

How to change my code?

Upvotes: 1

Views: 6628

Answers (1)

Metroids
Metroids

Reputation: 20477

Different ways to go about this depending on what you want your html to look like:

<tbody>
  <tr th:each="trn,iterStat : ${trans}">  
    <td th:text="${trn.txn ? 'Yes' : 'No'}" />
  </tr>
</tbody>

or

<tbody>
  <tr th:each="trn,iterStat : ${trans}">  
    <td>
      <span th:if="${trn.txn}">Yes</span>
      <span th:unless="${trn.txn}">No</span>
    </td>
  </tr>
</tbody>

Upvotes: 6

Related Questions