- Issue created by @danchadwick
Hey Dan, this sounds about right to me, at some point, I slowly tried to convert them but seems like I never finished. That aside, I don't believe there would be any breaking change with this, so feel free to get this going.
Thanks a lot
- Merge request !127Issue #3502025: Twig default filter makes it hard to decline a default value → (Merged) created by Unnamed author
- 🇮🇳India sandip
I have perfrom the suggested changes to all component templates. Please review the MR.
- 🇺🇸United States danchadwick Boston
@sandippoddar - Thank you for the MR. I think this is too aggressive. We need to distinguish two different types of situations regarding defaulted arguments.
1. The template must have a value and if none is supplied, either by a null value or by another "falsey" value, such as an empty string or empty array, then the default should be supplied. This is where the
default()
filter is useful. The one tricky case is when the default is supplying a boolean, because the default filter will turn a boolean false value into true. Here the ?? operator is useful.2. The template wants a value where a falsey value is a perfectly valid default and a distinction must be made between no default (null) and a falsey default. The example I gave is supplying extra "utility" classes to be added to other classes in the template. Here the use of the ?? operator to supply the default only when no argument value is supplied (null) and not override a falsey default like the empty set [].
Make sense?
- 🇮🇳India sandip
Thanks for the feedback now it is clear to me i am working on it.
- 🇮🇳India sandip
Hi @danchadwick, I have done the changes can you please share your feedback on it.
- Status changed to RTBC
30 days ago 5:20pm 14 May 2025 - 🇮🇳India Tirupati_Singh
Hi all, I've also attempted to replicate this issue while working with the components. For example, with the "Carousel" component, when I passed the following values:
show_carousel_control: true
,
show_carousel_indicators: false
,
show_carousel_caption: false
,
the carousel still rendered indicators and captions, even though false was explicitly set for those props. This behavior was consistent across other components as well, whenever the default('true') filter was used. As @danchadwick mentioned in comment #6, the default filter was causing this unexpected behavior.I applied the provided MR as a patch, and it applied cleanly without any issues. After the patch was applied, I observed the components working as expected. Specifically, replacing the default('true') filter with the null coalescing operator (??) resolved the problem. Now, when passing show_carousel_control: true, show_carousel_indicators: false, and show_carousel_caption: false, the carousel no longer renders the indicators or captions, as expected.
I've attached screenshots demonstrating the change and its effect on the component for reference. I am moving the issue status to RTBC, as the changes are now working as intended across the components.
Thanks!
Automatically closed - issue fixed for 2 weeks with no activity.