I need Thymeleaf to always include a label element but only conditionally show a value for it.
If message.type is equal to warning it should show the message.text. Otherwise, the HTML DOM should still contain the label element.
I've tried this but then the label element is missing from the HTML when the message.type is not equal to warning.
<label id="message" th:if="${message.type == 'warning'}" th:value="${message.text}" th:text="${message.text}"></label> I'm trying to accomplish something like this:
<label id="message" th:value="${message.type=='warning' ? message.text: ''}" th:text="${message.type=='warning'? message.text: ''"></label> If the message.type is warning, I would expect HTML like this:
<label id="message">My warning message</label> Otherwise, I would like to have HTML like this:
<label id="message"></label>