ux: AlpineJS specific attributes are not rendered (`@click` and `x-on:click`)
I love the components, so thank you ❤️
I have a button component and I would like to be able to do:
<twig:Button value="Toggle" x-on:click="open = !open"/>
but the x-on:click attribute is not rendered with this Twig:
<button{{ attributes }}>{{ value }}</button>
instead it just strips the attribute and outputs:
<button>Toggle</button>
If I try to use the @click syntax, Twig throws an exception.
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 26 (16 by maintainers)
Commits related to this issue
- minor #1960 [TwigComponent] allow attributes to be prefixed with `@` (kbond) This PR was merged into the 2.x branch. Discussion ---------- [TwigComponent] allow attributes to be prefixed with `@` ... — committed to symfony/ux by kbond 2 years ago
- bug #2328 [TwigComponent] Ignore "nested" for Alpine & Vue attributes (smnandre) This PR was squashed before being merged into the 2.x branch. Discussion ---------- [TwigComponent] Ignore "nested" ... — committed to symfony/ux by Kocal 2 years ago
Big thanks to @smnandre for fixing the
@issue in #1966! As discussed, we’ll forgo escaping:for now.In my experience, x-on and @ are pretty much always interchangeable. When using Alpine with Laravel Blade, there are occasionally conflicts using the @ syntax since Blade uses @ for it’s directives.
Long story short, I can’t think of any downsides to supporting @ prefixes on attributes and using that syntax for Twig components.
You’re the best, @kbond. Thank you 🎉
I don’t think we will change the nested contract.
But, i checked, you cannot create a blog
foo-bar, so i really think we could change the nested regex to consider x-on as an attribute and not a nested prop 🤷