3
votes

I just created a new Spring Boot v1.5 project and facing issue where Thymeleaf Layout Dialect is not working.

I have the dependencies in my build.gradle and its on the classpath.

compile group: 'nz.net.ultraq.thymeleaf', name: 'thymeleaf-layout-dialect', version: '2.1.2'

I have the following layout file

    <!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:th="http://www.thymeleaf.org"
      xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout">
<head>
    <meta charset="UTF-8" />
    <title>Default Template</title>
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta name="author" content="" />
    <meta name="description" content="" />
    <meta name="title" content="" />
    <link rel="stylesheet" media="screen" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" />
</head>
<body>

    <!-- header -->
    <header th:include="shared/nav-menu :: menu-admin" />

    <!-- page content -->
    <th:block>
        <section layout:fragment="content"></section>
    </th:block>

</body>
</html>

And file with content:

    <!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:th="http://www.thymeleaf.org"
      xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
      layout:decorator="default">
<head>
    <title>Parameter Manager</title>
</head>
<body>
    <section layout:fragment="content">
        <h2>OMG I am on the page!</h2>
    </section>
</body>
</html>

The HTML output is content.html file. It is not working as intended. The header and navigation menu should be part of the HTML output. Also the is in the page source which should not be the case.

1
If you view:source, do you still see the layout:fragment and layout:decorator attributes, or are they gone? Have you tried other thymeleaf tags to see if your template is being evaluated at all? - Metroids
Yes in my login.html that doesn't use layout dialect thymeleaf works fine. I've used this same setup a while ago but it was Spring Boot 1.2 or 1.3 at the time so maybe something changed. - greyfox

1 Answers

3
votes

Apparently the latest version of Thymeleaf Layout Dialect doesn't work with Spring Boot 1.5. Using version 1.2.9 and it works as expected.

compile group: 'nz.net.ultraq.thymeleaf', name: 'thymeleaf-layout-dialect', version: '1.2.9'