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
I am currently working on a project in which StimulusJs and Twig components are being used together. I just looked in the documentation, it seems to me that there is no way to add a Stimulus controller using the Stimulus Twig helpers.
It is not possible to add a controller or action like this because only attributes are allowed, which results in an error.
Expected attribute name when parsing the "<twig:Button" syntax.
I could pass the controller or action to the component via a prop, but this would make the components much more complex. Ultimately, we used the stimulus data attributes as a fallback. This means we lose all the benefits of the stimulus twig helper functions.
This is not possible, and will not for some time. In short, the TwigComponent HTML syntax is syntaxic.. sugar.
A template containing
<twig:Foobar="foobar" />
is in fact transliterated into
{{ component('Foo', {bar: "foobar"}) }}
There is no way to use for nor it is to pass attrbute strings here, as Twig prevent it.
On a broader angle, as Twig component allow props: they need keys to accept values.
But, you absolutely can do this:
{% setattributes=action.attr %} {# not using immediately because i have a doubt for parenthesis and dot notation here #}
<twig:Button {{ ...attributes }} />
As long attributes is a map of things indexed by string keys.. this should work for you.
:)
In short: you have to deal with "conditions" outside the component call, but that can be done quite easily :)
I am currently working on a project in which StimulusJs and Twig components are being used together. I just looked in the documentation, it seems to me that there is no way to add a Stimulus controller using the Stimulus Twig helpers.
It is not possible to add a controller or action like this because only attributes are allowed, which results in an error.
Expected attribute name when parsing the "<twig:Button" syntax.
I could pass the controller or action to the component via a prop, but this would make the components much more complex. Ultimately, we used the stimulus data attributes as a fallback. This means we lose all the benefits of the stimulus twig helper functions.
Is there a better way to add these stimulus twig helper functions, or what would be required to allow them?
The text was updated successfully, but these errors were encountered: