【问题标题】:Wrapping block to other block thymeleaf将块包装到其他块百里香
【发布时间】:2016-05-12 09:35:45
【问题描述】:

我有两个百里香叶片段如下

<div th:fragment="inputText">
  <input type="text"/>
</div>

<div th:fragment="fieldSet"></div>

要将文本框包含到字段集中,我尝试将其称为

<div th:include="fieldSet">
  <th:block th:include="inputText/>
</div>

这不包括 fieldSet 中的 inputText。它只呈现 fieldSet。

有没有办法在片段中包含片段?

【问题讨论】:

    标签: html dom layout fragment thymeleaf


    【解决方案1】:

    无法看到您应用的全貌,但在我看来,您正在尝试在此处完成模板继承。如果是这样,我鼓励您使用例如集成到 Spring Boot Thymeleaf 启动器中的“Thymeleaf Page Layouts”。

    通过使用Thymeleaf Page Layouts,您可以分层组织模板,具有父页面模板,然后是特定控制器方法的子模板。如果需要,此子模板可以包含父模板并重新定义父模板上的不同部分。

    【讨论】:

      猜你喜欢
      • 2021-05-03
      • 1970-01-01
      • 1970-01-01
      • 2012-09-21
      • 2020-12-30
      • 2013-09-10
      • 1970-01-01
      • 1970-01-01
      • 2021-01-09
      相关资源
      最近更新 更多