#How to include a thymeleaf template into another one, to include header, footer etc
1 messages · Page 1 of 1 (latest)
⌛ This post has been reserved for your question.
Hey @gusty knot! Please use
/closeor theClose Postbutton above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically marked as dormant after 300 minutes of inactivity.
TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.
you can use fragments for that
do u recommend having a page with header, content, footer
and then changing the content like i want to
yes
ok
so i make a main page with header, menu, content, footer
and then when i want to return something else i can change automatically the content
but load the same page
well the content could be in every page
since that's what differs between pages
so idk whether you want that
yeah
so like i make a header, content, footer
and i inject in the content div
for every page different content
is that what fragments are for
well if content changes between pages
doesnt it make sense to change that
?
The goal of a fragment is if you have the same thing over and over, you can include that and don't have to write it over and over
oh damn ye
that good
i can then include header, footer and nav menu
and just change content
yeah
<link rel="stylesheet" href="header.css">
<header>
<h1>Programme annuel des etudiants</h1>
</header>
this is my header.html
Well you'd have one HTML where you have a block that you want to insert
will it include the css automatically
?
Essentially you can have a HTML that contains something like
<th:block th:fragment="header">
<link rel="stylesheet" href="header.css">
<header>
<h1>Programme annuel des etudiants</h1>
</header>
</th:block>
and then you can do something like
<th:block th:replace="your/html/file/containing/the/header.html :: header" />
after the :: u put header too
does it mean i can have oen big general.html
with general stuff
and then access different stuff
header
that's the name of the fragment
you can have one HTML with multiple fragments
yeah so I can have one general.html with multiple fragments
yes
btw <th:block> just means Thymeleaf will insert that as-is
you can also use <div> or whatever and Thymeleaf will put it in a div
yeah if you want everything to be in a div, you could do that if you want to
kinda pointless imo
depends
Like if you have a navigation, the whole thing could be in a <nav> or <div> anyways
well just put those tags in ur general file
yeah I think so
I remember that being changed and updating stuff for it
your decision