thymeleaf / thymeleaf-docs

Thymeleaf documentation
Apache License 2.0
44 stars 54 forks source link

Prevent fragments without a signature being called with unnamed parameters #50

Closed danielfernandez closed 7 years ago

danielfernandez commented 7 years ago

If a fragment is inserted with an unnamed parameter:

<div th:insert="::f ('hello')">...</div>

...but the fragment signature has no parameters:

<div th:fragment="f">...</div>

This could provoke some confusion, because the users could think they are passing some needed information to the fragment that the fragment is actually ignoring.

This is specially confusing in /content() scenarios that might be used to emulate a th:include using a th:insert:

<div th:insert="::f/content() ('hello')">...</div>
<div th:fragment="f(message)">
   [[${message}]]
</div>

In the example above, the [[${message}]] expression would print nothing, because f/content() does not match the <div th:fragment="f(message)"> tag but its contents only. And its contents contain no signature.

In these cases, therefore, an exception should be raised warning that unnamed parameters cannot be used when there is no signature at the selected fragment.

danielfernandez commented 7 years ago

Oops, wrong repository to register this. The good one is thymeleaf/thymeleaf#603