【发布时间】:2020-05-27 09:47:15
【问题描述】:
我有一个具有标准页面布局和许多内容模板的应用程序。每个内容模板都可以有一个或多个我想将其视为片段的内容部分。我希望能够遍历每个片段并在放入格式化 div 后分别包含它。我的想法是,我不希望每个内容页面都必须知道如何嵌套 section 和 div 标签才能使页面正确格式化。我尝试了以下方法但没有成功:
layout.html:
<html xmlns:th="http://www.thymeleaf.org"
th:fragment="layout(contentFragments)">
<section class="row-outer-sm"
th:each="frag,iterStat : ${contentFragments}">
<div class="container">
<div class="row justify-content-center">
<div class="col">
<div th:if="${iterStat.first}"
th:replace="fragments/messages :: messages">
Messages go here
</div>
<div th:replace="${frag}">
Content goes here.
</div>
</div>
</div>
</div>
</section>
</html>
content.html:
<html lang="en"
xmlns:th="http://www.thymeleaf.org"
th:replace="fragments/layout :: layout(~{:: div.section-content})">
<div class="section-content">
Some things for my first section
</div>
<div class="section-content">
Some things for my second section
</div>
</html>
content.html 中的片段表达式正确地找到了所有具有 section-content 类的 div,但它们似乎作为单个连接片段传递到 layout.html。有什么方法可以获取可用于“th:each”标签的片段列表?
【问题讨论】:
标签: thymeleaf