所有Thymeleaf片段在一个.html文件中,选择一个来使用。

huangapple go评论82阅读模式
英文:

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.)

huangapple
  • 本文由 发表于 2020年8月11日 10:45:32
  • 转载请务必保留本文链接:https://go.coder-hub.com/63350756.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定