Head and Title in Thymeleaf

前端 未结 7 1157
我寻月下人不归
我寻月下人不归 2021-01-31 18:23

I\'m a Thymeleaf beginner. I started with a common layout page:

fragments/layout.html



        
相关标签:
7条回答
  • 2021-01-31 19:19

    Check out Parameterizable fragment signatures.

    Basically, in your fragment:

    <!DOCTYPE html>
    <html xmlns:th="http://www.thymeleaf.org">
    <head th:fragment="headerFragment (pageTitle)">
        <title th:text="${pageTitle}>Template title</title>
        <!-- metas, link and scripts -->
    </head>
    <body>
        <div class="container">
            Some text
        </div>
    </body>
    </html>
    

    Then, where you use it:

    <!DOCTYPE html>
    <html xmlns:th="http://www.thymeleaf.org">
    <head th:replace="fragments/layout :: headerFragment (pageTitle='Bla Bla Some Title'">
        <title>Page title</title>
        <!-- metas, link and scripts -->
    </head>
    <body>
        <div class="container">
            Some text
        </div>
    </body>
    </html>
    
    0 讨论(0)
提交回复
热议问题