首页 > 解决方案 > 如何在百里香中将一个html页面包含到另一个页面?

问题描述

我在 Spring Boot 应用程序中有以下项目结构 -

/templates/home/index.html

/templates/includes/header.html

我想在索引文件中包含头文件。我已经尝试了链接 - https://stackoverflow.com/questions/23538693/include-html-page-in-thymeleaf# =

但冒号 '::' 显示错误。

我是百里香的新手。谁能解释一下?谢谢。

标签: springspring-mvcspring-bootthymeleaf

解决方案


感谢所有试图帮助我的人。我解决了以下问题 -

//header.html
<div th:fragment="header">
<!-- related code of header file >
</div>



//index.html
//to include header follow the code( the header file is inside includes directory) 
<div th:replace="/includes/header :: header"> </div>

推荐阅读