2017-07-17 42 views
0

Thymeleaf 3具有內置片段支持(不需要nz.net.ultraq.thymeleaf:thymeleaf-layout-dialect依賴關係)。Thymeleaf 3頁面腳本標記的本地片段

我沒有經歷過與Thymeleaf並希望看到代碼,允許定義一些script標籤納入內部head標籤和之前</body>結束標記一些標籤列入。

回答

0

甲HTML文件像這樣...

<!DOCTYPE html> 
<html xmlns:th=「http://www.thymeleaf.org」> 
<head th:fragment=「head」> 
    <script> 
    … 
    </script> 
<head> 

<body> 
    <div th:fragment="foot"> 
     … 
    </div> 
    </body> 
</html> 

...限定兩個片段:headfoot然後可以用其他Thymeleaf模板被引用,像這樣:

<!DOCTYPE html> 
<html xmlns:th=「http://www.thymeleaf.org」> 
<head> 
    <!—/*/ <th:block th:include=「fragments/main :: head"><.th:block> /*/—> 

    … other stuff specific to this template 
</head> 
<body> 
    … other stuff specific to this template 

    <!—/*/ <th:block th:include=「fragments/main :: foot"><.th:block> /*/—> 
</body> 
</html> 

的包括指令(<th:block th:include=「fragments/main :: head")描述了包含片段(fragments/main)的文件的位置以及該文件中的特定片段的名稱(head),所以我的示例assu包含片段的HTML文件的名稱爲main,並且它位於相對於使用這些片段的模板文件的位置的名爲fragments的文件夾中。例如:

+- templates 
    | 
    +- fragments 
     | 
     + main.html 
    +- index.html 
    +- … etc