Search code examples
thymeleaf

Thymeleaf - how to condition format date value if exists?


I have a table that shows dates, but some date values are null or blank. I'd like to format them if they exist and display nothing if there's no value.

I was considering something like:

(date != '' ? ${#calendars.format(date,'dd-MM-yyyy HH:mm')} : '')

Is this possible? How?


Solution

  • Maybe you have to try something like this?

    <table>
    ....
        <td>
            <span th:if="${date != null}" 
                  th:text="${#calendars.format(date,'dd-MM-yyyy HH:mm')}">
            </span>
        </td>
    ....
    </table>
    

    If you have not null value in date it will shown another it will be blank table cell.