Reputation: 61
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
Upvotes: 5
Views: 7728
Reputation: 842
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.
Upvotes: 3
Reputation: 7095
In one.html you can include two.html by following this steps:
Include two.html in one.html by adding this line in one.html:
<div th:insert="two :: two"></div>
Include this bit of code in two.html just after the <body>
tag:
<div th:fragment="two">
This should include the bit of code surrended by the <div th:fragment="two">
into one.html
More info in the thymeleaf documentation
Upvotes: 1