Thymeleaf:将HTML添加到:替换函数

时间:2016-08-08 12:18:09

标签: html thymeleaf

我想在Thymeleaf的 th:replace 函数中添加一些HTML,如下所示:

<div th:replace="elements/listview :: row (subtext='Test<br />Test')" ></div>

我的'listview'模板是这样的:

 <div class="listview-row" th:fragment="row">
            <span class="listview-subtext" th:if="${subtext != null}" th:utext="${subtext}">

            </span>
        </div>

它无法编译。当然我希望它编译为:

 <div class="listview-row">
            <span class="listview-subtext">
                Test<br />Test
            </span>
        </div>

..随着HTML的到位。有没有办法做到这一点?提前感谢您的帮助。

1 个答案:

答案 0 :(得分:0)

试试这个:

&#13;
&#13;
<div class="listview-row" th:fragment="row(subtext)">
            <span class="listview-subtext" th:if="${subtext != null}" th:utext="${subtext}">

            </span>
        </div>
&#13;
&#13;
&#13;

并像这样使用它:

&#13;
&#13;
<div th:replace="elements/listview :: row ('Test<br />Test')" ></div>
&#13;
&#13;
&#13;