【发布时间】:2017-12-24 06:48:10
【问题描述】:
使用 Thymeleaf 3,可以通过 ~{:: selector} 语法将片段从页面传递到模板。
对该对象可以进行什么样的操作?
Fragment 可以在表达式中使用:
<div th:fragment="name(arg)">
<div th:replace="${arg} :? _"></div>
</div>
我可以只提取片段内的部分片段吗(以下是不正确的语法!!):
<div th:fragment="name(arg)">
<div th:replace="${arg :: script} :? _"></div>
<div th:replace="${arg}.filter('script'} :? _"></div>
<div th:replace="${xpath(${arg},'script')} :? _"></div>
</div>
更新我反省了用什么片段表达式来解决:
<th:block th:text="${bodyContent.class}" />
这是org.thymeleaf.standard.expression.Fragment。它有:
<th:block th:text="${bodyContent.templateModel.class}" />
TemplateModel 可以通过toString() 或write(Writer writer) 渲染。我看不到过滤Fragment 内容的简单方法...
【问题讨论】:
标签: thymeleaf