@@ -57,14 +57,27 @@ directory. In fact, you should have an example controller there already: ``hello
57
57
}
58
58
}
59
59
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:
61
69
62
70
.. code-block :: html+twig
63
71
64
72
<div {{ stimulus_controller('hello') }}>
65
73
...
66
74
</div>
67
75
76
+ <!-- would render -->
77
+ <div data-controller="hello">
78
+ ...
79
+ </div>
80
+
68
81
That's it! Whenever this element appears on the page, the ``hello `` controller
69
82
will activate.
70
83
@@ -159,6 +172,17 @@ Stimulus Twig Helpers
159
172
This bundle adds 3 Twig functions/filters to help add Stimulus controllers,
160
173
actions & targets in your templates.
161
174
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
+
162
186
stimulus_controller
163
187
~~~~~~~~~~~~~~~~~~~
164
188
@@ -243,6 +267,11 @@ there's also a ``stimulus_controller`` filter:
243
267
Hello
244
268
</div>
245
269
270
+ <!-- would render -->
271
+ <div data-controller="chart other-controller" data-chart-name-value="Likes">
272
+ Hello
273
+ </div>
274
+
246
275
You can also retrieve the generated attributes as an array, which can be helpful e.g. for forms:
247
276
248
277
.. code-block :: twig
0 commit comments