twigjs/twig.js

consider adding stimulus functions to create data attributes

tacman opened this issue · 1 comments

tacman commented

I love stimulusjs, and Symfony stimulus bundle makes it really easy to add stimulus controllers in twig.

Would you consider adding those same stimulus function to the core library, so that twigjs can generate the same? that is, the helpers here.

https://symfony.com/bundles/StimulusBundle/current/index.html#stimulus-twig-helpers

<div {{ stimulus_controller('chart', { 'name': 'Likes', 'data': [1, 2, 3, 4] }) }}>
    Hello
</div>

<!-- would render -->
<div
   data-controller="chart"
   data-chart-name-value="Likes"
   data-chart-data-value="&#x5B;1,2,3,4&#x5D;"
>
   Hello
</div>

I know it's a bit of a big ask, the code to generate the data attributes exists in PHP but converting it to javascript is, well, a bit complicated, at least for me. But if you happen to use stimulus, perhaps you'd consider it.

Thanks.

This library only includes the core functions, but does allow for extension, so you could add the helpers yourself or even release a package with them.