Skip to content

Instantly share code, notes, and snippets.

@mageddo
Last active March 24, 2019 15:07
Show Gist options
  • Save mageddo/ac8f4eb9b4cea3d40f6daedcc088afad to your computer and use it in GitHub Desktop.
Save mageddo/ac8f4eb9b4cea3d40f6daedcc088afad to your computer and use it in GitHub Desktop.

I think you are looking for 8.3 Flexible layouts The documantation is awesome and easy to follow, but here is also simple case for just inserting title string

layouts/layout.html

<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org" th:fragment="page(title)">
    <head th:replace="fragments/head :: common_header(title=${title})"></head>
    <body>
        <div th:replace="this :: content"></div>
    </body>
</html>

fragments/head.html

<!DOCTYPE html>
<html  xmlns:th="http://www.thymeleaf.org">
    <head th:fragment="common_header(title)">
        <title th:text="${title}">The awesome application</title>
    </head>
    <body></body>
</html>

index.html (indexTitle comes from controller or you can just put string there)

<html xmlns:th="http://www.thymeleaf.org"
      th:include="layouts/layout :: page(title=${indexTitle})">
    <head></head>
    <body>
        <section th:fragment="content">
           <div class="block">Part of index.html</div>
        </section>
    </body>
</html>

And here is also simplified github demo from one of my project you can play with

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment