Allow fragment parameters to have default values
See original GitHub issueIt would be great if fragment parameters could have default values:
<div th:fragment="frag (param = 'hello')">
Issue Analytics
- State:
- Created 9 years ago
- Reactions:4
- Comments:11 (9 by maintainers)
Top Results From Across the Web
Thymeleaf, fragments and default parameters - Stack Overflow
The best way to allow optional parameter for a fragment is to declare them with "th:with" and describe them with meaningful default values....
Read more >SafeArgs: partial default values in an action produce wrong ...
We should always put arguments without a default value before those with a default value, following the order on the destination itself within...
Read more >Default parameters - JavaScript - MDN Web Docs
Default function parameters allow named parameters to be initialized with default values if no value or undefined is passed.
Read more >Pass data between destinations - Android Developers
Destination-level arguments and default values are used by all actions that navigate to the destination. If needed, you can override the default ......
Read more >Variables - Relay
GraphQL variables are a construct that allows referencing dynamic values ... Fragments can also reference variables that have been declared by a query:....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@git2snap the idea is that, at the fragment side, a
th:with
can assign a default value to a parameter that is not given it (or is null).Note that parameters appearing in the signature (
frag(par1,par2)
) are required, so we would have two options:First option:
Which we could call in several ways (note using named parameters as in the last line we can include parameters that are not in the signature):
Second option:
Which requires us to specify both parameters (nulling the second one if needed):
@JavaWebinar please note that
th:replace
has greater precedence thanth:with
, so in your tag:That
th:replace
will execute, replace the tag, and therefore make thatth:with
simply disappear. So it will never execute and yourimg
local variable will be never given a value.If you want to specify that additional parameter, you can do: