symfony / ux

Symfony UX initiative: a JavaScript ecosystem for Symfony

Home Page:https://ux.symfony.com/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Twig Component with Stimulus Attributes

TomoyaHamasaki opened this issue · comments

How does one use stimulus when using a component?

<twig:Component {{ stimulus_controller('example') }} />

I can't do this as I can with a typical element. Is the only way to achieve this goal is by doing this?

<twig:Component data-controller="example" />

Yes the HTML syntax allows you to only add attribute to your component and can't parse twig directly like that

<twig:Component {{ stimulus_controller('example') }} />

@TomoyaHamasaki here you can use the ... syntax

<twig:Component {{ ...stimulus_controller('example') }} />

:)

<twig:Component {{ stimulus_controller('example') }} />

@TomoyaHamasaki here you can use the ... syntax

<twig:Component {{ ...stimulus_controller('example') }} />

:)

I love you, but why does that work? lol what is ...?

It's a spread operator (destructuring) borrowed from JavaScript