Thymeleaf layout dialect and th:replace in head causes title to be blank

前端 未结 3 501
我寻月下人不归
我寻月下人不归 2021-01-12 06:30

I\'m following this tutorial: http://www.thymeleaf.org/doc/layouts.html (got to Thymeleaf Layout Dialect section). In there you can find an example:



        
3条回答
  •  别那么骄傲
    2021-01-12 07:01

    Finally, I've found a way to achieve what I wanted.

    In layout file </code> tag <strong>must</strong> stay. All other tags I grouped with <code><object></code> tag and annotated it as follows:</p> <pre><code><head> <title layout:title-pattern="$CONTENT_TITLE">Layout Title will be replaced by Page Title!

    In my html/components/head.htm file I had to remove </code> tag so it won't be duplicated after include. </p> <pre><code><head th:fragment="head"> <meta charset="utf-8" /> <!-- NO TITLE TAG HERE --> ... </head> </code></pre> <p>This way head fragment is <strong>included</strong> in <code><object></code> tag and thanks to <code>th:remove="tag"</code> <code><object></code> tag gets removed and my final HTML output is:</p> <pre><code><head> <title>My content title ...

    Obviously, I removed NO TITLE TAG HERE message too, once I got it working.

    提交回复
    热议问题