How do you display a variable’s value in Thymeleaf?

How do you display a variable’s value in Thymeleaf?

A) [[${variable}]]
B) {{variable}}
C) ${variable}
D) $[variable]

Answer:

A) [[${variable}]]

Explanation:

In Thymeleaf, the double square brackets [[${variable}]] are used to display the value of a variable within an HTML element. This syntax ensures that the value is properly escaped and rendered as text in the browser.

For example:


<p>Hello, [[${name}]]!</p>

In this example, the value of the name variable is displayed inside a paragraph element.

Reference links:

https://www.javaguides.net/p/thymeleaf-tutorial.html

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top