Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to select direct child (using /) #978

Open
maio opened this issue Oct 20, 2023 · 1 comment
Open

Unable to select direct child (using /) #978

maio opened this issue Oct 20, 2023 · 1 comment

Comments

@maio
Copy link

maio commented Oct 20, 2023

Hello,

I'm trying to write following template:

    <div th:replace="~{:: my-fragment(icon=~{:: /span})}">
        <span class="icon">X</span>
    </div>

    <th:block th:remove="all">
        <div th:fragment="my-fragment(icon)">
            my-fragment <span th:replace="${icon}"></span>
        </div>
    </th:block>

According to markup selector syntax (if I read it correctly) ~{:: /span} should select span inside current node.

But it seems that ~{:: /span} on line 1 is unable to select <span>Hello</span> and pass it to my-fragment.

@duoduobingbing
Copy link

duoduobingbing commented Dec 1, 2023

I have run into this myself as well.

The documentation states

The basic syntax includes:
/x means direct children of the current node with name x.

However /sth seems to select all <sth> that are a direct descendant of the document root instead of the direct descendants of the current node.

In your case

    <div th:ref="example" th:replace="~{:: my-fragment(icon=~{:: example/span})}">
        <span class="icon">X</span>
    </div>

    <th:block th:remove="all">
        <div th:fragment="my-fragment(icon)">
            my-fragment <span th:replace="${icon}"></span>
        </div>
    </th:block>

should work

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants