Search code examples
springspring-mvcspring-bootthymeleaf

How to include one html page to another in thymeleaf?


I have the following project structure in Spring Boot Application -

/templates/home/index.html

/templates/includes/header.html

I want to include the header file inside the index file. I have tried the link - https://stackoverflow.com/questions/23538693/include-html-page-in-thymeleaf#=

But the colon '::' is showing error.

I am new to thymeleaf. Can anybody explain? Thanks.


Solution

  • Thanks all who tried to help me. I solved the problem as follows -

    //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>