You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feature #589 [Twig] Add a strategy for adding a Stimulus controller to a Twig component (weaverryan)
This PR was squashed before being merged into the 2.x branch.
Discussion
----------
[Twig] Add a strategy for adding a Stimulus controller to a Twig component
…onent root element
| Q | A
| ------------- | ---
| Bug fix? | yes-ish
| New feature? | yes
| Tickets | Fix#527
| License | MIT
Hi!
This allows adding a custom Stimulus controller to the root element of a component. The syntax is:
```
<div {{ attributes.add(stimulus_controller('my-controller', { someValue: 'foo' })) }}>
```
This is a compromise of having a nice syntax vs not duplicating code. The `attributes.add()` method is designed to work specifically with the `stimulus_*` functions, so it's name is kinda funny. But it feels way better than something like `attributes->stimulusController(stimulus_controller())`. Just doing `attributes.stimulusController('my-controller')` isn't possible at the moment, because it would require us to create a `StimulusControllersDto` and that, unfortunately, requires a Twig Environment for escaping purposes.
Cheers!
Commits
-------
2d2a137 [Twig] Add a strategy for adding a Stimulus controller to a Twig component
0 commit comments