New Thymeleaf user here, the documentation on the site is really very good. I've been through it all and the relevant posts on the forum.
I've got some idea of how to achieve the basic level of template inheritance I want but I can't make it materialise in code form.
I'd like to have a root template that looks like this (pseudo code):
<html> <head/> !-- contains all core css and js --
<body> <header/> !-- a thymeleaf fragment --
<div id="main"/> !-- a thymeleaf include ? --
<footer/> !-- a thymeleaf fragment --
<div/> !-- contains all remaining js resources --
And a child page:
<thymeleaf include> !-- the <div id="main"> section --
My page </thymeleaf include>
I have a query about fragments too, the code in the Tutorial Guide shows a full page layout (including doctype... etc) for a fragment:
> I have a query about fragments too, the code in the Tutorial Guide shows a full page layout (including doctype... etc)
> Is the reason it's defined with all the other tags to present a valid XML document to the parser to extract the fragment from?
Yes, the parser needs a valid XML document unless you have configured Thymeleaf with the template mode "Legacy HTML5".
The problem with this approach is the page fragment would contain the core information such as the main stylesheet which makes viewing the page with just the browser quite useless.
Thanks for all the suggestions, I really like the XML namespace approach to templating afforded by Thymeleaf as well as the opportunity to use direct browser rendering during development by the web designers. I think I'll just bite the bullet and mirror the code for the <head/> across each page. It will be a pain to update by hand... but the hope is I won't have to do it too often.