La Carbonell
La Carbonell

Reputation: 2066

Thymeleaf: Html tag inside a th:text

Is it possible to have Html tag inside a th:text ?

for instance:

<h2 th:text="'LOCATION INFO Device &lt;strong&gt;' + ${deviceKey} + ' &lt;/strong&gt;  at ' + ${deviceEventTime} ">

Upvotes: 6

Views: 6232

Answers (2)

Orion87
Orion87

Reputation: 1

It's possible with this syntax [(${brand})]:

<h3 th:object="${brand}" class="text-center text-black mt-5">
All Products By Brand 
<span>
    <b class="text-danger">[(${brand})]</b>
</span>

The object in this case is a String, but you can use ${object.something}.

Upvotes: 0

Metroids
Metroids

Reputation: 20487

Yes, what you have works if you use th:utext instead of th:text.

<h2 th:utext="'LOCATION INFO Device &lt;strong&gt;' + ${deviceKey} + ' &lt;/strong&gt;  at ' + ${deviceEventTime}" />

I would personally format it like this, however:

<h2>
  LOCATION INFO Device 
  <strong th:text="${deviceKey}" />
  at
  <span th:text="${deviceEventTime}">
</h2>

(Which may or may not be possible, depending on your actual requirements.)

Upvotes: 8

Related Questions