英文:
All Thymeleaf fragments in one .html file, choose one to use
问题
我正在使用Thymeleaf,假设我有一个文件header.html:
<head th:fragment="fragA">...</head>
<head th:fragment="fragB">...</head>
<head th:fragment="fragC">...</head>
我想将header中的fragA插入到文件index.html中:
<html>
<head th:replace="fragA">...</head>
<body>
</body>
</html>
我能做到这一点吗?
英文:
I'm using thymeleaf and suppose I have a file header.html:
<head th:fragment="fragA">...</head>
<head th:fragment="fragB">...</head>
<head th:fragment="fragC">...</head>
And I want to take header fragA into the file index.html:
<html>
<head th:replace="fragA">...</head>
<body>
</body>
</html>
Am I able to do this.
答案1
得分: 1
你需要指定文件和片段:
<html>
<head th:replace="header :: fragA">...</head>
<body>
</body>
</html>
(我假设您是在Spring的上下文中执行此操作:根据您的解析器和默认模板后缀设置,您可能需要使用header.html。)
英文:
You need to specify the file and fragment:
<html>
<head th:replace="header :: fragA">...</head>
<body>
</body>
</html>
(I am assuming you are doing this in the context of Spring: You may need to use header.html depending on your resolver and default template suffix setting.)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论