Reputation: 1317
I need write text like: <td th:text="${ticket.eventName} + '<br />' + ${ticket.ticketType}">Event Name</td>
But Thymeleaf
return error because of <br />
. How I can solve this problem?
UPD: I try make like: <td th:text="${ticket.eventName} + #{nextline} + ${ticket.ticketType}">Event Name</td>
and this works. nextline
value = \n
, but #{nextline}
works only one time. If I paste it repeatedly it doesn't work, why?
UPD2: I solve this problem. Instead '<br />'
need paste '<br />'
and th:text
change to th:utext
.
Upvotes: 0
Views: 4456
Reputation: 18030
Tested for Thymeleaf 3.0:
<td th:utext="|${ticket.eventName} <br/> ${ticket.ticketType}|">Event Name</td>
Take note of th:utext tag
Other option:
<td>[[${ticket.eventName}]] <br/> [[${ticket.ticketType}]]</td>
See Inlined output expressions
Upvotes: 3
Reputation: 951
You can use th:inline:
<td th:inline="text">
[[${ticket.eventName}]]
<br/>
[[${ticket.ticketType}]]
</td>
More info: http://www.thymeleaf.org/doc/tutorials/2.1/usingthymeleaf.html#inlining
Upvotes: 3
Reputation: 1354
If you want to skip escaping the characters you can use th:block, which produces cleaner results.
th:block is a mere attribute container that allows template developers to specify whichever attributes they want. Thymeleaf will execute these attributes and then simply make the block dissapear without a trace. (http://www.thymeleaf.org/doc/tutorials/2.1/usingthymeleaf.html#synthetic-thblock-tag)
So in your example:
<td>
<th:block th:text="${ticket.eventName}"/>
<br/>
<th:block th:text="${ticket.ticketType}"/>
</td>
Upvotes: 2