【发布时间】:2020-12-31 01:06:35
【问题描述】:
我正在尝试创建一个片段来表示具有自定义内容的卡片。我想做类似的事情:
<div class="card" th:fragment="myfragment" th:utext="${content}">
</div>
然后用 as
<th:block th:replace="myfragment">
<p>Some custom content that would be the value of 'content'</p>
</th:block>
这将使处理更大的 html 变得更容易,而在属性中写入会有点难看。 (基本上我正在寻找与 Blade 的视图和插槽类似的功能)
编辑: 我知道片段参数化,但在属性中传递长而复杂的 html 代码非常难看且难以管理。
一个更具描述性的例子是一张卡片,它的卡片主体不是 p,而是一张桌子。
【问题讨论】:
-
你看过百里香布局方言吗?
-
Thymeleaf 支持参数化片段。 thymeleaf.org/doc/articles/layouts.html
标签: java html spring thymeleaf