Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions src/StimulusBundle/doc/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,34 @@ You can also retrieve the generated attributes as an array, which can be helpful

{{ form_row(form.password, { attr: stimulus_target('hello-controller', 'myTarget').toArray() }) }}

Chaining Different Helpers
~~~~~~~~~~~~~~~~~~~~~~~~~~

The ``stimulus_controller``, ``stimulus_action`` and ``stimulus_target``
filters can be mixed freely to render all the attributes of an element at
once, whichever function the chain started with:

.. code-block:: html+twig

<div {{ stimulus_controller('first-controller')
|stimulus_target('second-controller', 'anotherTarget')
|stimulus_target('third-controller', 'foo')
|stimulus_action('first-controller', 'test')
|stimulus_controller('fourth-controller')
|stimulus_action('fourth-controller', 'onClick') }}
>
Hello
</div>

<!-- would render -->
<div data-controller="first-controller fourth-controller"
data-action="first-controller#test fourth-controller#onClick"
data-second-controller-target="anotherTarget"
data-third-controller-target="foo"
>
Hello
</div>

.. _configuration:

Configuration
Expand Down
16 changes: 16 additions & 0 deletions src/StimulusBundle/tests/Twig/StimulusTwigExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -250,4 +250,20 @@ public function testAppendStimulusTarget()
(string) $extension->appendStimulusTarget($dto, '@symfony/ux-dropzone/dropzone', 'anotherTarget fooTarget')
);
}

public function testAppendDifferentStimulusHelpers()
{
$extension = new StimulusTwigExtension(new StimulusHelper($this->twig));
$dto = $extension->renderStimulusController('first-controller');
$dto = $extension->appendStimulusTarget($dto, 'second-controller', 'anotherTarget');
$dto = $extension->appendStimulusTarget($dto, 'third-controller', 'foo');
$dto = $extension->appendStimulusAction($dto, 'first-controller', 'test');
$dto = $extension->appendStimulusController($dto, 'fourth-controller');
$dto = $extension->appendStimulusAction($dto, 'fourth-controller', 'onClick');

$this->assertSame(
'data-controller="first-controller fourth-controller" data-action="first-controller#test fourth-controller#onClick" data-second-controller-target="anotherTarget" data-third-controller-target="foo"',
(string) $dto
);
}
}
Loading