Master pages / themes just with Thymeleaf

classic Classic list List threaded Threaded
2 messages Options
Ben
Reply | Threaded
Open this post in threaded view
|

Master pages / themes just with Thymeleaf

Ben
In the other thread it's mentioned that Thymeleaf works well together with Sitemesh but is this also possible with Thymeleaf using some kind of master pages? What I mean is this:

master.html:
<html>
<head>
</head>
<body>


<div th:fragment="content" />


</body>
</html>

What I would like to do is to insert content into the master page's content fragment. Is something like this possible with Thymeleaf?
Reply | Threaded
Open this post in threaded view
|

Re: Master pages / themes just with Thymeleaf

danielfernandez
Administrator
Hi,

Well, although I wouldn't really consider this an "elegant" solution, you could use a master.html page similar to the one you wrote, but the tag you'd have to use is "th:include" not "th:fragment" (the latter is used for defining the fragment to be included, not the placeholder actually used for inserting such fragment)

What you could do is use the ability to specify fragments in th:include using variables, like:

<html>
   ...
   <body>
      ...
      <div th:include="${myPage} :: ${myFragment}"></div>
      ...
   </body>
</html>

...and then use "master.html" as your "only" template but making sure that correct values for the "myPage" and "myFragment" variables are always included in the context when executing it (and of course, the values for these variables would change depending on your requirements).

Regards,
Daniel.