Thymeleaf 2.1 + Spring Boot - how do I create a master template and only inject the content part/fragment?

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Thymeleaf 2.1 + Spring Boot - how do I create a master template and only inject the content part/fragment?

java9
Hello!

So I'm using Spring Boot with the Thymeleaf dependency (which is currently version 2.1) and it's been great experience so far.

But, having to duplicate my template files is not so great. I did use some th:include / th:replace with some fragments but that unfortunately does not eleminate the need to make copies of the entire template/view file.

I'd like to know if there's a way to maintain only one template (master) file which may or may not contain other included/replaced fragments?

So le'ts say that for majority of my pages I want some layout to be used. I would then only create the files that contain the main content part.

Is that possible and how do I proceed, considering I'm using Spring Boot and have not had to basically touch anything apart from creating the template files in order to start using Thymeleaf.

Thank you.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Thymeleaf 2.1 + Spring Boot - how do I create a master template and only inject the content part/fragment?

Metroids
Yeah, for this you want to use the thymeleaf plugin "layout dialect".  You can read up about it here:

https://github.com/ultraq/thymeleaf-layout-dialect

It has a different version for thymeleaf 2 vs 3, so make sure you get the right version.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Thymeleaf 2.1 + Spring Boot - how do I create a master template and only inject the content part/fragment?

java9
Thank you, will look into that.

Do you happen to know if anyone proposed to Thymeleaf that this functionality makes it into the core (for me it's a must-have feature)?
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Thymeleaf 2.1 + Spring Boot - how do I create a master template and only inject the content part/fragment?

Metroids
I agree completely -- layout dialect should be a core feature.  Not sure if anyone has proposed anything like that though.
Loading...