Possible bug in th:fragment/replace (head named)

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Possible bug in th:fragment/replace (head named)

miguel
I use for example:

test.html
< th th:fragment="head(param)">
   hi < span th:text="${param}">
< /th>

< div th:replace="test :: head('john smith')"></div>

and it doesn't work, the result:
hi
(param ignored)

If I change 'head' with "heads" or another name it works, the result:
hi john smith

"head" is a special work?
Reply | Threaded
Open this post in threaded view
|

Re: Possible bug in th:fragment/replace (head named)

miguel
Any idea?
Reply | Threaded
Open this post in threaded view
|

Re: Possible bug in th:fragment/replace (head named)

danielfernandez
Administrator
From the fact that "param" is a reserved word in 3.0 I'm assuming you are using Thymeleaf 2.1. And from the fact that your <span> tag is not correctly closed, I'm assuming you are using the (deprecated in 3.0) LEGACYHTML5 template mode.

The LEGACYHTML5 template mode applies a tag balancer before letting Thymeleaf parse the template, and this modifies the actual template markup that reaches Thymeleaf. Indeed, this could be modifying the contents of your fragment depending on, for example, whether "<span>" is an allowed tag inside a "<th>" (nekoHTML, the tag balancer, could be closing your <th> just before starting the <span>).

Also, the "x" syntax (in this case "head") is an alias for both "//x", meaning "any tag called 'x' at any level", and "%x", meaning "any reference --i.e. in this case fragment-- called 'x'". So your fragment name can be ambiguous if your template also contains a <head> tag.

So what I'd do is rename "head" to something else or use "%head" instead, then also rename "param" to something other in order to prepare for Thymeleaf 3.0, close that "<span>" tag and finally, if possible, switch to a different template mode like HTML5 which does not require tag balancing (but requires you to properly close your tags). Unless you switch to Thymeleaf 3.0, which would not mind at all about the well-formed-ness of your markup.

Regards,
Daniel.