-
-
Notifications
You must be signed in to change notification settings - Fork 364
[Twig] Add a strategy for adding a Stimulus controller to a Twig component #589
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
9764aa6
to
2d2a137
Compare
Hey.... I've just stumbled upon this issue as the feature is already in the docs but not released yet. Could you pack a new version with this change? Cheers |
Oooh, we need to add the versionadded annotation above the docs for this to make it clear! We’ll have as new release sometime soon… but not immediately. |
Added in sha: 8e5cab3 |
@@ -94,4 +95,21 @@ public function without(string ...$keys): self | |||
|
|||
return $clone; | |||
} | |||
|
|||
public function add(AbstractStimulusDto $stimulusDto): self |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't a bit weird to have a method add
that takes a StimulusDto
?
Shouldn't this method be named withStimulus
or something like that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably :). But it looked a bit terrible when used:
{{ attributes.withStimulus(stimulus_controller(...)) }}
The 2x Stimulus. But, we could potentially "open" this add()
method later to accept other types of arguments, if we think of something.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, an array of key/values for example
Thanks for fixing the doc. I'm totally fine with using a non-release for trying things out. I just felt that integrating custom/legacy JS is quite common use case. |
…onent root element
Hi!
This allows adding a custom Stimulus controller to the root element of a component. The syntax is:
This is a compromise of having a nice syntax vs not duplicating code. The
attributes.add()
method is designed to work specifically with thestimulus_*
functions, so it's name is kinda funny. But it feels way better than something likeattributes->stimulusController(stimulus_controller())
. Just doingattributes.stimulusController('my-controller')
isn't possible at the moment, because it would require us to create aStimulusControllersDto
and that, unfortunately, requires a Twig Environment for escaping purposes.Cheers!