Skip to content

Commit 8fa1e58

Browse files
bocharsky-bwweaverryan
authored andcommitted
Add a note about using raw data attributes as a prefered way
1 parent 8fe391d commit 8fa1e58

File tree

1 file changed

+30
-1
lines changed

1 file changed

+30
-1
lines changed

src/StimulusBundle/doc/index.rst

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,27 @@ directory. In fact, you should have an example controller there already: ``hello
5757
}
5858
}
5959
60-
Use the Twig functions from this bundle to activate your controllers:
60+
Then, activate the controller in your HTML:
61+
62+
.. code-block:: html+twig
63+
64+
<div data-controller="hello">
65+
...
66+
</div>
67+
68+
Optionally, this bundle has a Twig function to render the attribute:
6169

6270
.. code-block:: html+twig
6371

6472
<div {{ stimulus_controller('hello') }}>
6573
...
6674
</div>
6775

76+
<!-- would render -->
77+
<div data-controller="hello">
78+
...
79+
</div>
80+
6881
That's it! Whenever this element appears on the page, the ``hello`` controller
6982
will activate.
7083

@@ -159,6 +172,17 @@ Stimulus Twig Helpers
159172
This bundle adds 3 Twig functions/filters to help add Stimulus controllers,
160173
actions & targets in your templates.
161174

175+
.. note::
176+
177+
Though this bundle provides these helpful Twig functions/filters, it's
178+
recommended to use raw data attributes instead, as they're straightforward.
179+
180+
.. tip::
181+
182+
If you use PhpStorm IDE - you may want to install
183+
[Stimulus plugin](https://plugins.jetbrains.com/plugin/18940-stimulus)
184+
to get nice auto-completion for the attributes.
185+
162186
stimulus_controller
163187
~~~~~~~~~~~~~~~~~~~
164188

@@ -243,6 +267,11 @@ there's also a ``stimulus_controller`` filter:
243267
Hello
244268
</div>
245269

270+
<!-- would render -->
271+
<div data-controller="chart other-controller" data-chart-name-value="Likes">
272+
Hello
273+
</div>
274+
246275
You can also retrieve the generated attributes as an array, which can be helpful e.g. for forms:
247276

248277
.. code-block:: twig

0 commit comments

Comments
 (0)