0

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 '&lt;br /&gt;' and th:text change to th:utext.

4
  • change <br /> to <br></br> here is an explanation Commented Feb 18, 2016 at 9:28
  • @Enigo Unfortunately it returns the same error Commented Feb 18, 2016 at 9:30
  • Have you tried th:utext instead of th:text? Commented Feb 18, 2016 at 9:34
  • @Enigo yes, I have and it doesn't work too Commented Feb 18, 2016 at 9:35

3 Answers 3

3

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

Sign up to request clarification or add additional context in comments.

Comments

3

Tested for Thymeleaf 3.0:

<td th:utext="|${ticket.eventName} &lt;br/&gt; ${ticket.ticketType}|">Event Name</td>

Take note of th:utext tag

Other option:

<td>[[${ticket.eventName}]] <br/> [[${ticket.ticketType}]]</td>

See Inlined output expressions

Comments

2

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>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.