Parent layout transfer template using thymeleaf

I just decided to start a small project with spring-boot and thymeleaf.

thimeleaf itself looks amazing so far, but my question is what is the best way to get it, e.g. layout.html, which brings a basic page layout

as
- general css inclusions
- general inclusions js
- basic structure (e.g., column layout 2/3)

which is wrapped around the contents of individual pages (viewing a blog post, viewing comments, viewing images in a gallery, etc.), that I don’t need to transfer general material to all templates.

so far, the only way I've found is to use fragmented inclusions, but I'm not sure if this is the right approach to get the full structure around the template that I want to display for the current request.

how can i get the <div class="content"></div> arround my template?

Hope someone can help.

early

+6
source share
2 answers

You have several options: Tiles Extension, Layout Dialect - you can find it on the Ecosystem page here: http://www.thymeleaf.org/ecosystem.html

And a proprietary approach (without any extension) described in this comment:

http://blog.codeleak.pl/2013/11/is-it-worth-upgrading-to-thymeleaf-21.html?showComment=1383817035384#c5722173744814267184

Hope this helps.

+5
source

Spring Boot has ready-made support for LayoutDialect (in our opinion, this is the best option). You just need to add the correct versions of everything in your classpath. There's a sample that uses this approach .

+5
source

Source: https://habr.com/ru/post/957728/


All Articles