0

Hello I am building an application in Spring Boot and Thymeleaf and I have a paragraph that I want to make it appear only if it has a value. If it does not I do not want it to appear.

Here is the code that I have tried:

<h2 th:text="'Raspuns: ' + ${raspuns}" th:disabled="${raspuns}==null"></h2>

But when I enter the page it says: Raspuns: null I want to make that dissapear.

JohnNewman
  • 29
  • 1
  • 10
  • There is no `

    ` element in the code fragment in the question. What exactly is it that you want to show/hide, here? The `

    ` element, or something else?

    – andrewJames May 26 '22 at 12:47
  • 1
    Maybe you just want to use a Thymeleaf `if` statement: `

    `. [How to do a th:if statement in thymeleaf?](https://stackoverflow.com/questions/41620438/how-to-do-a-thif-statement-in-thymeleaf)
    – andrewJames May 26 '22 at 12:55

1 Answers1

0

try this:

<h2 th:if="${raspuns} != null" th:text="'Raspuns: ' + ${raspuns}"></h2>

see more about conditions in the documentation:

Thymeleaf Conditional Evaluation

Rafael da Silva
  • 302
  • 2
  • 13