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

Reimplement th:include/th:substituteby/th:replace syntax with new DOM Selector syntax #205

Closed
danielfernandez opened this issue Aug 17, 2013 · 0 comments

Comments

@danielfernandez
Copy link
Member

Currently, as of 2.0.x, the th:include (or th:substituteby, or th:replace) syntax makes a difference between:

<div th:include="mytemplate :: myfragment">...</div>

...which means look for a tag in the mytemplate template that is marked as th:fragment="myfragment" and:

<div th:include="mytemplate :: [//div[@id='myfragment']]">...</div>

...which means look for a <div>tag in the mytemplate template that is marked as id="myfragment".

There is, therefore, a difference in syntax between the first type of fragment selection, which is based on th:fragment and the second one, which has to be specified between brackets ([...]) and is based on the execution of a DOM Selector.

Applying the new syntax

In order to achieve the more integrated syntax that will be later needed to implement #180, we need to be able to specify DOM Selector -based fragment selections without the surrounding brackets, as:

<div th:include="mytemplate :: //div[@id='myfragment']">...</div>

...and this means we should be able to integrate the search for th:fragment="myfragment" into the DOM Selector syntax, so that everything (both tag selection based on paths/attributes and also the search for th:fragment) is a DOM Selector.

How can this be done? By means of the new capabilities of DOM Selectors implemented in #202. Specifically, by considering th:fragment attributes as a node reference, and implementing its search as an implementation of the DOMSelector.INodeReferenceChecker interface.

Thanks to that, the following syntaxes should be equivalent:

<div th:include="mytemplate :: myfragment">...</div>
<div th:include="mytemplate :: %myfragment">...</div>

..and we should be able to express the id-attribute based selection we saw above also in several equivalent ways:

<div th:include="mytemplate :: //div[@id='myfragment']">...</div>
<div th:include="mytemplate :: div[@id='myfragment']">...</div>
<div th:include="mytemplate :: div#myfragment">...</div>
<div th:include="mytemplate :: #myfragment">...</div>

Refer to #202 for more information on all the possibilities of this DOM Selector syntax.

Finally, note this th:fragment node reference mechanism should be able to identify fragment names even if they contain parameters, so that:

<div th:fragment="myfragment (oneparam, twoparam)">...</div>

Should be correctly referenceable as %myfragment.

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

1 participant