thymeleaf模板 在html中引入另一个html
1.这是一个 head.html 页面
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf">
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<div th:fragment="headname">
我是头部这里...
</div>
</body>
</html>
主要代码:
<div th:fragment="headname">
这里面写内容....
</div>
2.welcome.html
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf">
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<!--引入头部head.html-->
<div th:include="head :: headname"></div>
</body>
</html>
其中注意一点:这里的“include=head” 其中head为你引用的页面的名字**
<div th:include="head :: headname"></div>
要注意一点: “::” 这个符号前后要有空格才可以
还有一个也可以引入:
th:replace 也可以引入模块
th:include:引入子模块的children,依然保留父模块的tag。
加载模板的内容: 读取加载节点的内容(不含节点名称),替换div内容。
th:replace:引入子模块的所有,不保留父模块的tag。
替换当前标签为模板中的标签,加载的节点会整个替换掉加载他的div。
更多推荐
thymeleaf模板 在html中引入另一个html
发布评论