Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Include html page in thymeleaf

Tags:

thymeleaf

I have 2 HTML files, suppose one.html and two.html. In one.html I want to include two.html.

In JSF I can do it like that:

It means that inside one.xhtml file, I can include two.xhtml.

How can we do it in *.html file? in thymeleaf

like image 516
user3610906 Avatar asked Sep 30 '22 20:09

user3610906


1 Answers

you can do it easily. could you share your header.html file?

or, let me show a bit like I do for my projects

in header.html put in side the <body> a code:

<div th:fragment="client_header">
    <p>This is for client</p>
</div>

<div th:fragment="admin_header">
    <p>This is for admin</p>
</div>

and let's say you want to add client_header into the index.html. Do follow these in your index.html page (inside <body>)

<div th:replace="includes/header :: client_header">
</div>

note: includes/header before :: refers the html path (excludes .html) and client_header after :: refers the part in header.html you want to insert.

I hope you understand everything that I have explain here.

like image 175
testuser Avatar answered Oct 03 '22 11:10

testuser