Skip to content

Nested layout:replace causes a problem #37

@moravcik

Description

@moravcik

I have a thymeleaf template with nested layout:fragments:

<html xmlns="http://www.w3.org/1999/xhtml" 
    xmlns:th="http://www.thymeleaf.org" 
    xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout">

<!--/* accordion-group layout defined */-->
<div layout:fragment="accordion-group" th:remove="all">
    <div>accordion header</div>
    <div layout:fragment="accordion-inner">accordion inner X</div>
</div>

<!--/* accordion-group layout used */-->
<div layout:include="nested-layout-problem::accordion-group">
    <div layout:fragment="accordion-inner">accordion inner
        <th:block th:with="i=1">
        <!--/* contractList layout defined and used */-->
        <div layout:fragment="contractList(i)">
            <th:block th:text="|contract list ${i}|"></th:block>
            <th:block layout:fragment="removeEmailFromList">remove from 1</th:block>
        </div>
        <!--/* contractList layout used */-->
        </th:block>
        <div layout:replace="nested-layout-problem::contractList(2)">
            <th:block layout:fragment="removeEmailFromList">remove from 2</th:block>
        </div>
        <!--/* contractList layout used */-->
        <div layout:replace="nested-layout-problem::contractList(3)">
            <th:block layout:fragment="removeEmailFromList">remove from 3</th:block>
        </div>
    </div>
</div>

</html>

Processed template output is following:

<html xmlns="http://www.w3.org/1999/xhtml">
<div>
    <div>accordion header</div>
    <div>accordion inner
        <div>
            contract list 1
            remove from 3
        </div>
        <div>
            contract list 2
            remove from 2
        </div>
        <div>
            contract list 3
            remove from 3
        </div>
    </div>
</div>
</html>

Please note the lines:
contract list 1
remove from 3 --> there should be remove from 1 instead

Problem is not present when I use the layout:include instead of layout:replace

<div layout:include="nested-layout-problem::contractList(2)">
...
<div layout:include="nested-layout-problem::contractList(3)">

or when I define the nested fragment separately:

<div layout:fragment="contractList(i)" th:remove="all">
    <th:block th:text="|contract list ${i}|"></th:block>
    <th:block layout:fragment="removeEmailFromList">remove from X</th:block>
</div>

Full example code here:
https://gist.github.com/moravcik/9412935

Metadata

Metadata

Assignees

Labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions