Process Thymeleaf Variable as HTML Code and Not Text

Process Thymeleaf variable as HTML code and not text

You can use th:utext attribute that stands for unescaped text (see documentation). Use this with caution and avoid user input in th:utext as it can cause security problems.

<div th:remove="tag" th:utext="${n}"></div>

Display a string that contains HTML in Thymeleaf template

You can use th:utext (unescaped text) for such scenarios.

Simply change

<p th:text="${content.text}"></p>

to

<p th:utext="${content.text}"></p>

I will suggest to also have a look into documentation here to know all about using Thymeleaf.

Thymeleaf : display a variable containing html tags

Use th:utext instead of th:text

http://www.thymeleaf.org/doc/tutorials/2.1/usingthymeleaf.html#unescaped-text

Why the Html text inside html element does not concatenate with the Thyme-leaf text? code be

That's just not how thymeleaf works. th:text and th:utext replace the contents of the tag.

The th:text attribute ... sets the result as the body of the host tag, effectively replacing the ... text we see in the code.

There are plenty of ways to accomplish what you want though. For example, to append at the end:

<h1 id="font">
Hello does concat with message.
<span th:utext="${message}" />
</h1>

Or

<h1 th:utext="|Hello does concat with message. ${message}|" id="font" />

Thymeleaf th:text - Put a text without removing HTML structures

I faced the same problem. The answer is th:inline='text'

This should solve your issue

<h1 th:inline="text" >
[[${header.title}]]
<small th:text="${header.subtitle}">Subtitle</small>
</h1>

or you can also use th:remove="tag"

<h1>
<span th:text="${header.title}" th:remove="tag">title</span>
<small th:text="${header.subtitle}" >Subtitle</small>
</h1>


Related Topics



Leave a reply



Submit