Search code examples
springtemplatesmodel-view-controllerdynamicthymeleaf

Dynamic pages that keep footer and header but replace content?


im making a spring boot application with thymeleaf i have a bit of trouble finding a solution for the following.

I want my page to have a directory that follows a template like

<header></header>
misc...
<content>
{DYNAMIC}
</content>
<footer></footer>

For example at "/posts/{3}" the {DYNAMIC} would be replaced with the content of post with id = 3.

I have researched a bit and i have seen fragments etc but im not sure how i can build them from the server.

Thanks


Solution

  • You can use Thymeleaf Utraq Dialect to help you create a base template and then use then decorate your blog detail page with the base template.

    The base template will have header and footer and provide a dynamic section and the blog detail page will just provide the data for the dynamic section. You can see my answer here on how to use the dialect.