Head and Title in Thymeleaf

前端 未结 7 1156
我寻月下人不归
我寻月下人不归 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:13

    I was also having this problem (Thank you nmy for referencing the documentation!) Here is what I noticed and how I solved it in my app:

    Things to note from the documentation:

    1. The differences between th:include and th:replace
    2. Referencing fragments by domselector instead of by th:fragment
    3. Thymeleaf provides a "this" option for finding selectors

    With these 3 things in mind, you can do the following:

    fragments/layout.html:

    
        Layout Generic Title< /title>
        <!-- metas, link and scripts -->
    </head>
    </code></pre>
    
    <p>page.html</p>
    
    <pre><code><head th:include="fragments/layout :: headerFragment">
        <title id="pageTitle">Page title
        
    
    

    Hope this helps!

提交回复
热议问题