[英]HTML tags inside Thymeleaf
I need write text like: <td th:text="${ticket.eventName} + '<br />' + ${ticket.ticketType}">Event Name</td>
But Thymeleaf
return error because of <br />
. 我需要这样写文本: <td th:text="${ticket.eventName} + '<br />' + ${ticket.ticketType}">Event Name</td>
但是Thymeleaf
由于<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. UPD:我尝试像这样: <td th:text="${ticket.eventName} + #{nextline} + ${ticket.ticketType}">Event Name</td>
,它可以正常工作。 nextline
value = \\n
, but #{nextline}
works only one time. nextline
值= \\n
,但是#{nextline}
仅工作一次。 If I paste it repeatedly it doesn't work, why? 如果我重复粘贴它不起作用,为什么?
UPD2: I solve this problem. UPD2:我解决了这个问题。 Instead '<br />'
need paste '<br />'
相反, '<br />'
需要粘贴'<br />'
and th:text
change to th:utext
. 和th:text
更改为th:utext
。
If you want to skip escaping the characters you can use th:block, which produces cleaner results. 如果要跳过转义字符,可以使用th:block,产生更清晰的结果。
th:block is a mere attribute container that allows template developers to specify whichever attributes they want. th:block是仅属性容器,允许模板开发人员指定所需的任何属性。 Thymeleaf will execute these attributes and then simply make the block dissapear without a trace. Thymeleaf将执行这些属性,然后简单地使该块消失而无任何痕迹。 ( http://www.thymeleaf.org/doc/tutorials/2.1/usingthymeleaf.html#synthetic-thblock-tag ) ( 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>
You can use th:inline: 您可以使用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 更多信息: http : //www.thymeleaf.org/doc/tutorials/2.1/usingthymeleaf.html#inlining
Tested for Thymeleaf 3.0: 经过Thymeleaf 3.0测试:
<td th:utext="|${ticket.eventName} <br/> ${ticket.ticketType}|">Event Name</td>
Take note of th:utext tag 注意th:utext标签
Other option: 其他选择:
<td>[[${ticket.eventName}]] <br/> [[${ticket.ticketType}]]</td>
See Inlined output expressions 请参见内联输出表达式
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.