ultraq / thymeleaf-layout-dialect

A dialect for Thymeleaf that lets you build layouts and reusable templates in order to improve code reuse
https://ultraq.github.io/thymeleaf-layout-dialect/
Apache License 2.0
700 stars 111 forks source link

Merge strategy using conditional blocks around head tags #212

Open dtrunk90 opened 3 years ago

dtrunk90 commented 3 years ago

There seems to be an issue using conditional tags in the layout template:

<head>
    <th:block th:if="${false}">
        <title>test</title>
    </th:block>
</head>

The whole condition will be ignored and the title inside will be processed/rendered. However this is working:

<head>
    <title th:if="${false}">test</title>
</head>

Tested with version 2.5.1.

ultraq commented 3 years ago

To merge the titles of the layout and content pages, the layout dialect will select the <title> element wherever it is within <head>, and in the process completely bypass any conditions outside of the element, hence why the conditions aren't hit in your first code example but they are hit in your second.

I can't think of a workaround for this at the moment as special processing of <title> is needed so that you only end up with one <title> in the final HTML 🤔

dtrunk90 commented 3 years ago

Well, lets leave it open. In the meantime we can use the second approach as a workaround. Maybe you or I or someone else will have a good idea in the future.