ux
ux copied to clipboard
[Twig] Add `attributes()` twig function
| Q | A |
|---|---|
| Bug fix? | no |
| New feature? | no |
| Issues | n/a |
| License | MIT |
This allows passing attributes to elements easier.
<div{{ attributes({foo: 'bar'})>
When/if #1413 is merged, the following will also be possible:
<twig:Some:Component {{ ...attributes({foo: 'bar'}) }} />
Similar twig core issues/PRs: https://github.com/twigphp/Twig/pull/3930, https://github.com/twigphp/Twig/issues/3907, https://github.com/twigphp/Twig/pull/3760
The function name attributes is unfortunate as it can be confused with the attributes parameter in twig/live components:
<div{{ attributes }}> {# correct #}
<div{{ attributes() }}> {# wrong #}
html_attr() maybe?
That's a great idea, it would also close #940 since the main idea was to easily renders attributes
The function name attributes is unfortunate as it can be confused with the attributes parameter in twig/live components:
Yes, I agree here. I like html_attr but also attr as it's proposed in the Twig issue.
How it's gonna work with Live components for example?
<div attributes({role: 'alert', class='text-blue-800 px-4', ...attributes})>
...
</div>
Would love to have this in Twig itself :)