Spring Thymeleaf Layout 101 — The beauty of template engine.

Oli H.
2 min readApr 10, 2019

--

So you are not satisfied with the data-layout-fragment, eh?

Photo by Safar Safarov on Unsplash

You are in good hands! Here’s a new trick — data-layout-decorate!

The beat part is:

<html data-layout-decorate="~{layouts/default_layout.html}" lang="en">

This is what makes layout-decorate a possibility!

Now you have unleash the real templating power!

Step #1 — login Page

Step #2 — default_layout page

Just don’t forget your good old thymeleaf dependency.

Especially the layout-dialect
<dependency>
<groupId>nz.net.ultraq.thymeleaf</groupId>
<artifactId>thymeleaf-layout-dialect</artifactId>
</dependency>

So, there you go, let’s do it properly and set it up for success!

Feel free to like, share, comment below share your thoughts about pros and cons of this quick approach.

--

--

Oli H.

Software Engineer w/ Docker, Cloud& Data specialty.