2016-05-12 49 views
0

我有兩個thymeleaf片段如下包裝塊到其它塊thymeleaf

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

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

要包括文本框入字段集,我試圖調用它像

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

此內字段集不包括的inputText。它只呈現fieldSet。

有什麼辦法可以在片段中包含片段嗎?

回答

0

看不到您的應用程序的整個圖片,但在我看來,您正試圖在此完成模板的繼承。如果是這樣,我會鼓勵你使用'Thymeleaf Page Layouts',它集成到Spring Boot Thymeleaf啓動器中。

通過使用Thymeleaf Page Layouts您可以組織hierarchicaly具有特定的控制器方法父頁面tamplate然後孩子tamplates你的模板。如果需要,此子模板可以包含父模板並重新定義父模板上的不同部分。