Text

Thymeleaf allows to assign entire text to element or embed value into exist text of element.

  • th:text="<value>" - assigns text to current element, all elements in <value> will be removed
  • th:utext="<value>" - assigns unescaped text to current element, all elements in <value> will be saved
  • [[<value>]] - embeds <value> into current text, all elements in <value> will be removed
  • [(<value>)] - embeds unescaped <value> into current text, all elements in <value> will be saved
<!-- Let book.description equal to "This is very <b>interesting</b> book." -->

<!-- result will be 
<p>This is very interesting book.</p>
-->
<p th:text=${book.description}></p>

<!-- result will be 
<p>This is very <b>interesting<b> book.</p>
-->
<p th:utext=${book.description}></p>

<!-- result will be 
<div>
And this book has description: This is very interesting book.
</div>
-->
<div>
And this book has description: [[${book.description}]]
</div>

<!-- result will be 
<div>
And this book has description: This is very <b>interesting<b> book.
</div>
-->
<div>
And this book has description: [(${book.description})]
</div>