### Manual Setup with Webpack Encore
Source: https://context7.com/symfony/stimulus-bundle/llms.txt
Enable the Stimulus bridge in `webpack.config.js` and bootstrap the Stimulus app in `assets/bootstrap.js` for manual setup with Webpack Encore.
```javascript
// webpack.config.js
Encore
// …
.enableStimulusBridge('./assets/controllers.json')
;
```
```javascript
// assets/bootstrap.js
import { startStimulusApp } from '@symfony/stimulus-bridge';
export const app = startStimulusApp(require.context(
'@symfony/stimulus-bridge/lazy-controller-loader!./controllers',
true,
/\.[jt]sx?$/
));
```
--------------------------------
### Install StimulusBundle via Composer
Source: https://github.com/symfony/stimulus-bundle/blob/3.x/doc/index.rst
Use this command to install the StimulusBundle package using Composer.
```bash
composer require symfony/stimulus-bundle
```
--------------------------------
### Manual Setup with AssetMapper
Source: https://context7.com/symfony/stimulus-bundle/llms.txt
Register the asset path and bootstrap entries manually in `importmap.php` and `assets/bootstrap.js` when not using Symfony Flex.
```php
// importmap.php
return [
// …existing entries…
'@symfony/stimulus-bundle' => [
'path' => '@symfony/stimulus-bundle/loader.js',
],
'@hotwired/stimulus' => [
'version' => '3.2.2',
],
];
```
```javascript
// assets/bootstrap.js
import { startStimulusApp } from '@symfony/stimulus-bundle';
const app = startStimulusApp();
```
--------------------------------
### Basic Stimulus Controller Example
Source: https://github.com/symfony/stimulus-bundle/blob/3.x/doc/index.rst
A simple Stimulus controller that connects and updates its element's text content. This is a foundational example for creating custom controllers.
```javascript
import { Controller } from '@hotwired/stimulus';
export default class extends Controller {
connect() {
this.element.textContent = 'Hello Stimulus! Edit me in assets/controllers/hello_controller.js';
}
}
```
--------------------------------
### Initialize Stimulus App with AssetMapper
Source: https://github.com/symfony/stimulus-bundle/blob/3.x/doc/index.rst
The bootstrap.js file content when using AssetMapper, which starts the Stimulus application.
```javascript
import { startStimulusApp } from '@symfony/stimulus-bundle';
const app = startStimulusApp();
```
--------------------------------
### Configure Stimulus Controller in controllers.json
Source: https://github.com/symfony/stimulus-bundle/blob/3.x/doc/index.rst
Example of how a Stimulus controller is registered in the controllers.json file, including its enabled status and fetch mode.
```json
{
"controllers": {
"@symfony/ux-chartjs": {
"chart": {
"enabled": true,
"fetch": "eager"
}
}
},
"entrypoints": []
}
```
--------------------------------
### Add Stimulus UX Package to package.json
Source: https://github.com/symfony/stimulus-bundle/blob/3.x/doc/index.rst
Example of how a Stimulus UX package is added as a file dependency in package.json.
```json
{
"devDependencies": {
"...": "",
"@symfony/ux-chartjs": "file:vendor/symfony/ux-chartjs/assets"
}
}
```
--------------------------------
### startStimulusApp() - JavaScript / AssetMapper Bootstrap
Source: https://context7.com/symfony/stimulus-bundle/llms.txt
Starts the Stimulus `Application`, registers eagerly-loaded controllers immediately, and sets up a `MutationObserver` for lazy controllers, loading them only when a matching `data-controller` element appears.
```APIDOC
## `startStimulusApp()` — JavaScript / AssetMapper Bootstrap
Starts the Stimulus `Application`, registers all eagerly-loaded controllers immediately, and sets up a `MutationObserver`-based loader for lazy controllers so they are only fetched when a matching `data-controller` element appears in the DOM.
```javascript
// assets/bootstrap.js (with AssetMapper)
import { startStimulusApp } from '@symfony/stimulus-bundle';
const app = startStimulusApp();
// - Starts Stimulus Application
// - Reads eagerControllers map → registers immediately
// - Reads lazyControllers map → loads via dynamic import() on demand
// - Sets app.debug = true when Symfony runs in debug mode
```
```
--------------------------------
### Stimulus Bundle Importmap Configuration
Source: https://github.com/symfony/stimulus-bundle/blob/3.x/doc/index.rst
Example of how the Stimulus Bundle and Hotwired Stimulus are added to the importmap.php file when using AssetMapper.
```php
return [
// ...
'@symfony/stimulus-bundle' => [
'path' => '@symfony/stimulus-bundle/loader.js',
],
'@hotwired/stimulus' => [
'version' => '3.2.2',
],
];
```
--------------------------------
### Get Stimulus Controller Attributes as Array
Source: https://github.com/symfony/stimulus-bundle/blob/3.x/doc/index.rst
Retrieve the generated Stimulus controller attributes as a PHP array using the .toArray() method, useful for form attribute integration.
```twig
{{ form_start(form, { attr: stimulus_controller('hello', { 'name': 'World' }).toArray() }) }}
```
--------------------------------
### Get Stimulus Action Attributes as Array
Source: https://github.com/symfony/stimulus-bundle/blob/3.x/doc/index.rst
Retrieve the generated Stimulus action attributes as a PHP array using the .toArray() method, useful for form row integration.
```twig
{{ form_row(form.password, { attr: stimulus_action('hello-controller', 'checkPasswordStrength').toArray() }) }}
```
--------------------------------
### Bootstrapping Stimulus Application with AssetMapper
Source: https://context7.com/symfony/stimulus-bundle/llms.txt
The `startStimulusApp()` JavaScript function initializes the Stimulus `Application`. It handles registration of eager controllers and sets up a lazy loader for controllers that are fetched on demand when their corresponding elements appear in the DOM.
```javascript
// assets/bootstrap.js (with AssetMapper)
import { startStimulusApp } from '@symfony/stimulus-bundle';
const app = startStimulusApp();
// - Starts Stimulus Application
// - Reads eagerControllers map → registers immediately
// - Reads lazyControllers map → loads via dynamic import() on demand
// - Sets app.debug = true when Symfony runs in debug mode
```
--------------------------------
### Initialize Stimulus App with Webpack Encore
Source: https://github.com/symfony/stimulus-bundle/blob/3.x/doc/index.rst
The bootstrap.js file content when using Webpack Encore, which registers Stimulus controllers.
```javascript
import { startStimulusApp } from '@symfony/stimulus-bridge';
// Registers Stimulus controllers from controllers.json and in the controllers/ directory
export const app = startStimulusApp(require.context(
'@symfony/stimulus-bridge/lazy-controller-loader!./controllers',
true,
/\.[jt]sx?$/
));
```
--------------------------------
### Configure Stimulus Bundle Paths
Source: https://context7.com/symfony/stimulus-bundle/llms.txt
Override default controller discovery paths and `controllers.json` location in `config/packages/stimulus.yaml`. You can add additional paths for controllers.
```yaml
# config/packages/stimulus.yaml
stimulus:
controller_paths:
- '%kernel.project_dir%/assets/controllers'
- '%kernel.project_dir%/assets/admin/controllers' # additional path
controllers_json: '%kernel.project_dir%/assets/controllers.json'
```
--------------------------------
### Activate Stimulus Controller in HTML
Source: https://github.com/symfony/stimulus-bundle/blob/3.x/doc/index.rst
Demonstrates how to activate a Stimulus controller by adding the 'data-controller' attribute to an HTML element.
```html+twig
...
```
--------------------------------
### Configure Lazy Controller in controllers.json
Source: https://context7.com/symfony/stimulus-bundle/llms.txt
Mark a UX package controller as lazy by setting `"fetch": "lazy"` in `assets/controllers.json`. This defers loading until the element is in the DOM.
```json5
// assets/controllers.json — make a UX package controller lazy
{
"controllers": {
"@symfony/ux-chartjs": {
"chart": {
"enabled": true,
"fetch": "lazy" // ← deferred until element is in DOM
}
}
},
"entrypoints": []
}
```
--------------------------------
### Render Stimulus Action with Parameters
Source: https://github.com/symfony/stimulus-bundle/blob/3.x/doc/index.rst
Pass parameters to a Stimulus action using the stimulus_action() function. These parameters will be rendered as data attributes.
```html+twig
Hello
```
```html+twig
Hello
```
--------------------------------
### Configure Stimulus Bundle Paths
Source: https://github.com/symfony/stimulus-bundle/blob/3.x/doc/index.rst
Configure custom paths for Stimulus controllers and the controllers.json file in Symfony's configuration.
```yaml
stimulus:
# the default values
controller_paths:
- '%kernel.project_dir%/assets/controllers'
controllers_json: '%kernel.project_dir%/assets/controllers.json'
```
--------------------------------
### Render Stimulus Controller with Outlets
Source: https://github.com/symfony/stimulus-bundle/blob/3.x/doc/index.rst
Define Stimulus outlets for a controller using the stimulus_controller() function. This allows controllers to reference other elements in the DOM.
```html+twig
Hello
```
```html+twig
Hello
```
```html+twig
Hello
```
--------------------------------
### Stimulus Controller with Values, Classes, and Outlets in Twig
Source: https://context7.com/symfony/stimulus-bundle/llms.txt
Combine controller values, CSS classes, and outlets using the `stimulus_controller` function. This allows for comprehensive Stimulus attribute generation in a single call.
```twig
Modal
{#
→
Modal
#}
```
--------------------------------
### Basic Stimulus Controller in Twig
Source: https://context7.com/symfony/stimulus-bundle/llms.txt
Use the `stimulus_controller` Twig function to render a `data-controller` attribute. This is useful for basic controller attachment.
```twig
Hello
{# →
Hello
#}
```
--------------------------------
### Render Stimulus Actions
Source: https://github.com/symfony/stimulus-bundle/blob/3.x/doc/index.rst
Use the stimulus_action() function to render data attributes for Stimulus actions, specifying the controller, method, and optionally an event.
```html+twig
Hello
```
```html+twig
Hello
```
```html+twig
Hello
```
```html+twig
Hello
```
--------------------------------
### Programmatic Stimulus Attribute Creation in PHP
Source: https://context7.com/symfony/stimulus-bundle/llms.txt
Use `StimulusHelper::createStimulusAttributes()` in PHP services to programmatically create Stimulus attributes. This DTO allows adding controllers, actions, and targets before rendering.
```php
use Symfony\UX\StimulusBundle\Helper\StimulusHelper;
class CartFormType extends AbstractType
{
public function __construct(private StimulusHelper $stimulusHelper) {}
public function buildForm(FormBuilderInterface $builder, array $options): void
{
$stimulusAttrs = $this->stimulusHelper->createStimulusAttributes();
$stimulusAttrs->addController('cart', ['currency' => 'EUR', 'taxRate' => 0.2]);
$stimulusAttrs->addAction('cart', 'recalculate', 'change');
$builder->add('quantity', NumberType::class, [
'attr' => $stimulusAttrs->toArray(),
// Produces:
// 'data-controller' => 'cart',
// 'data-cart-currency-value' => 'EUR',
// 'data-cart-tax-rate-value' => '0.2',
// 'data-action' => 'change->cart#recalculate',
]);
}
}
```
--------------------------------
### Render Stimulus Controller with Values and Classes
Source: https://github.com/symfony/stimulus-bundle/blob/3.x/doc/index.rst
Use the stimulus_controller() function to render data attributes for a Stimulus controller, including values and CSS classes. Non-scalar values are JSON-encoded and all values are escaped.
```html+twig
Hello
```
```html+twig
Hello
```
```html+twig
Hello
```
```html+twig
Hello
```
```html+twig
Hello
```
--------------------------------
### Make Stimulus Controller Lazy Load
Source: https://github.com/symfony/stimulus-bundle/blob/3.x/doc/index.rst
Add the 'stimulusFetch: \'lazy\'' comment to a Stimulus controller to enable lazy loading. This prevents the controller from being downloaded on initial page load.
```javascript
import { Controller } from '@hotwired/stimulus';
/* stimulusFetch: 'lazy' */
export default class extends Controller {
// ...
}
```
--------------------------------
### Mark Controller as Lazy
Source: https://context7.com/symfony/stimulus-bundle/llms.txt
Add `/* stimulusFetch: 'lazy' */` to a controller to defer its loading until the element first appears in the DOM. This moves the controller into the lazy registry at asset-compile time.
```javascript
// assets/controllers/chart_controller.js
import { Controller } from '@hotwired/stimulus';
/* stimulusFetch: 'lazy' */
export default class extends Controller {
static values = { url: String };
connect() {
// Only loaded when
first appears
fetch(this.urlValue)
.then(r => r.json())
.then(data => this.renderChart(data));
}
renderChart(data) { /* … */ }
}
```
--------------------------------
### StimulusAttributes DTO - Full API
Source: https://context7.com/symfony/stimulus-bundle/llms.txt
The `StimulusAttributes` object accumulates controllers, actions, and targets, and can be serialized to an HTML attribute string or a plain array. It provides methods to add controllers, actions, targets, and arbitrary attributes.
```APIDOC
## `StimulusAttributes` DTO — Full API
The `StimulusAttributes` object accumulates controllers, actions, and targets and can be serialised to an HTML attribute string or a plain array.
```php
use Symfony\UX\StimulusBundle\Dto\StimulusAttributes;
// Obtained via StimulusHelper::createStimulusAttributes()
$attrs = $stimulusHelper->createStimulusAttributes();
// Add a controller with values, CSS classes, and outlets
$attrs->addController(
'@symfony/ux-dropzone/dropzone', // normalised → symfony--ux-dropzone--dropzone
['maxSize' => 5242880, 'accept' => 'image/*'],
['dragging' => 'border-blue-500'],
['preview' => '.preview-container']
);
// Add an action with parameters
$attrs->addAction('dropzone', 'upload', 'drop', ['maxFiles' => 10]);
// Add a named target
$attrs->addTarget('dropzone', 'fileInput');
// Add arbitrary extra attributes
$attrs->addAttribute('id', 'file-upload-widget');
// Render as an HTML attribute string (used directly in Twig {{ attrs }})
echo (string) $attrs;
// data-controller="symfony--ux-dropzone--dropzone"
// data-symfony--ux-dropzone--dropzone-max-size-value="5242880"
// data-symfony--ux-dropzone--dropzone-accept-value="image/*"
// data-symfony--ux-dropzone--dropzone-dragging-class="border-blue-500"
// data-symfony--ux-dropzone--dropzone-preview-outlet=".preview-container"
// data-action="drop->dropzone#upload"
// data-dropzone-max-files-param="10"
// data-dropzone-target="fileInput"
// id="file-upload-widget"
// Render as a PHP array (for form builders, etc.)
$array = $attrs->toArray();
// ['data-controller' => 'symfony--ux-dropzone--dropzone', ...]
// Iterate (implements IteratorAggregate)
foreach ($attrs as $name => $value) {
echo "$name=\"$value\"\n";
}
```
```
--------------------------------
### Full API for StimulusAttributes DTO in PHP
Source: https://context7.com/symfony/stimulus-bundle/llms.txt
The `StimulusAttributes` DTO, obtained via `StimulusHelper::createStimulusAttributes()`, allows detailed programmatic construction of Stimulus attributes. It supports adding controllers with values, CSS classes, outlets, actions with parameters, named targets, and arbitrary extra attributes.
```php
use Symfony\UX\StimulusBundle\Dto\StimulusAttributes;
// Obtained via StimulusHelper::createStimulusAttributes()
$attrs = $stimulusHelper->createStimulusAttributes();
// Add a controller with values, CSS classes, and outlets
$attrs->addController(
'@symfony/ux-dropzone/dropzone', // normalised → symfony--ux-dropzone--dropzone
['maxSize' => 5242880, 'accept' => 'image/*'],
['dragging' => 'border-blue-500'],
['preview' => '.preview-container']
);
// Add an action with parameters
$attrs->addAction('dropzone', 'upload', 'drop', ['maxFiles' => 10]);
// Add a named target
$attrs->addTarget('dropzone', 'fileInput');
// Add arbitrary extra attributes
$attrs->addAttribute('id', 'file-upload-widget');
// Render as an HTML attribute string (used directly in Twig {{ attrs }})
echo (string) $attrs;
// data-controller="symfony--ux-dropzone--dropzone"
// data-symfony--ux-dropzone--dropzone-max-size-value="5242880"
// data-symfony--ux-dropzone--dropzone-accept-value="image/*"
// data-symfony--ux-dropzone--dropzone-dragging-class="border-blue-500"
// data-symfony--ux-dropzone--dropzone-preview-outlet=".preview-container"
// data-action="drop->dropzone#upload"
// data-dropzone-max-files-param="10"
// data-dropzone-target="fileInput"
// id="file-upload-widget"
// Render as a PHP array (for form builders, etc.)
$array = $attrs->toArray();
// ['data-controller' => 'symfony--ux-dropzone--dropzone', ...]
// Iterate (implements IteratorAggregate)
foreach ($attrs as $name => $value) {
echo "$name=\"$value\"\n";
}
```
--------------------------------
### Stimulus Controller with Values in Twig
Source: https://context7.com/symfony/stimulus-bundle/llms.txt
Attach a Stimulus controller with scalar and JSON-serialised values using the `stimulus_controller` function. Ensure complex values like arrays are correctly JSON-encoded.
```twig
Search
{#
→
Search
#}
```
--------------------------------
### Enable Stimulus Bridge in Webpack Encore
Source: https://github.com/symfony/stimulus-bundle/blob/3.x/doc/index.rst
Configuration line to enable the Stimulus bridge in the webpack.config.js file when using Webpack Encore.
```javascript
.enableStimulusBridge('./assets/controllers.json')
```
--------------------------------
### Render Stimulus Targets
Source: https://github.com/symfony/stimulus-bundle/blob/3.x/doc/index.rst
Use the stimulus_target() function to render data attributes for Stimulus targets, specifying the controller and target names.
```html+twig
Hello
```
```html+twig
Hello
```
```html+twig
Hello
```
```html+twig
Hello
```
--------------------------------
### Stimulus Action with Typed Parameters in Twig
Source: https://context7.com/symfony/stimulus-bundle/llms.txt
Include typed action parameters in a Stimulus action by providing them as a key-value array to the `stimulus_action` function. These are automatically serialized.
```twig
{#
→
#}
```
--------------------------------
### Using `stimulus_controller` with Form Widgets
Source: https://context7.com/symfony/stimulus-bundle/llms.txt
Convert the output of `stimulus_controller` to an array using `.toArray()` when passing attributes to form widgets for proper integration.
```twig
{{ form_start(form, { attr: stimulus_controller('checkout', { step: 1 }).toArray() }) }}
```
--------------------------------
### Basic Stimulus Action in Twig
Source: https://context7.com/symfony/stimulus-bundle/llms.txt
Render a `data-action` attribute using `stimulus_action` to wire a DOM event to a Stimulus controller method. The default event is inferred if not specified.
```twig
{# → #}
```
--------------------------------
### Chain Stimulus Actions
Source: https://github.com/symfony/stimulus-bundle/blob/3.x/doc/index.rst
Chain multiple stimulus_action() calls or use the stimulus_action filter to apply multiple actions to a single element.
```html+twig
Hello
```
```html+twig
Hello
```
--------------------------------
### UX Package Controller Naming in Twig
Source: https://context7.com/symfony/stimulus-bundle/llms.txt
Use the `stimulus_controller` function for UX package controllers. The bundle automatically normalizes the controller name for correct Stimulus registration.
```twig
{# →
#}
```
--------------------------------
### Chaining Stimulus Actions with Twig Filter
Source: https://context7.com/symfony/stimulus-bundle/llms.txt
Chain multiple Stimulus actions onto the same element using the `stimulus_action` Twig filter. This allows a single element to trigger multiple controller methods.
```twig
{# → #}
```
--------------------------------
### StimulusHelper::createStimulusAttributes() - PHP Service
Source: https://context7.com/symfony/stimulus-bundle/llms.txt
Creates a mutable `StimulusAttributes` DTO in PHP services, form types, or controllers. This allows programmatic construction of Stimulus attributes without using Twig.
```APIDOC
## `StimulusHelper::createStimulusAttributes()` — PHP Service
Creates a mutable `StimulusAttributes` DTO inside PHP services, form types, or controllers, enabling programmatic construction of the same Stimulus attribute set without Twig.
```php
use Symfony\UX\StimulusBundle\Helper\StimulusHelper;
class CartFormType extends AbstractType
{
public function __construct(private StimulusHelper $stimulusHelper) {}
public function buildForm(FormBuilderInterface $builder, array $options): void
{
$stimulusAttrs = $this->stimulusHelper->createStimulusAttributes();
$stimulusAttrs->addController('cart', ['currency' => 'EUR', 'taxRate' => 0.2]);
$stimulusAttrs->addAction('cart', 'recalculate', 'change');
$builder->add('quantity', NumberType::class, [
'attr' => $stimulusAttrs->toArray(),
// Produces:
// 'data-controller' => 'cart',
// 'data-cart-currency-value' => 'EUR',
// 'data-cart-tax-rate-value' => '0.2',
// 'data-action' => 'change->cart#recalculate',
]);
}
}
```
```
--------------------------------
### Registering Stimulus Targets with Twig
Source: https://context7.com/symfony/stimulus-bundle/llms.txt
Use the `stimulus_target` Twig function to render `data-{controller}-target` attributes. It can register a single target or multiple target names in one call.
```twig
{# Single target #}
{# → #}
```
```twig
{# Multiple target names in one call #}
{# → #}
```
```twig
{# Use .toArray() in a form row #}
{{ form_row(form.email, {
attr: stimulus_target('validation', 'emailField').toArray()
}) }}
```
--------------------------------
### Render Stimulus Controller Attribute with Twig
Source: https://github.com/symfony/stimulus-bundle/blob/3.x/doc/index.rst
Utilizes the 'stimulus_controller' Twig function to render the necessary data attribute for activating a Stimulus controller.
```html+twig
...
```
--------------------------------
### Use Stimulus Controller in Twig
Source: https://github.com/symfony/stimulus-bundle/blob/3.x/doc/index.rst
Use the stimulus_controller() function in Twig to reference a Stimulus controller. This function normalizes the controller name for use in HTML attributes.
```html+twig
```
--------------------------------
### Chain Stimulus Controllers
Source: https://github.com/symfony/stimulus-bundle/blob/3.x/doc/index.rst
Chain multiple stimulus_controller() calls or use the stimulus_controller filter to apply multiple controllers and their attributes to a single element.
```html+twig
Hello
```
```html+twig
Hello
```
--------------------------------
### stimulus_target - Twig Filter
Source: https://context7.com/symfony/stimulus-bundle/llms.txt
Chains target registrations for different controllers on the same element, allowing multiple Stimulus targets to be applied to a single HTML element.
```APIDOC
## `stimulus_target` — Twig Filter (multiple controllers' targets)
Chains target registrations for different controllers on the same element.
```twig
{#
→
#}
```
```
--------------------------------
### Chaining Stimulus Targets for Multiple Controllers in Twig
Source: https://context7.com/symfony/stimulus-bundle/llms.txt
Chain the `stimulus_target` Twig filter to register targets for different controllers on the same HTML element.
```twig
{#
→
#}
```
--------------------------------
### Using `stimulus_action` with Form Fields
Source: https://context7.com/symfony/stimulus-bundle/llms.txt
Apply Stimulus actions to form fields by using `.toArray()` on the result of `stimulus_action` when setting the `attr` for form fields.
```twig
{{ form_row(form.password, {
attr: stimulus_action('password-strength', 'check', 'input').toArray()
}) }}
```
--------------------------------
### Chain Stimulus Targets
Source: https://github.com/symfony/stimulus-bundle/blob/3.x/doc/index.rst
Chain multiple stimulus_target() calls or use the stimulus_target filter to apply multiple targets from different controllers to a single element.
```html+twig
Hello
```
```html+twig
Hello
```
--------------------------------
### Chaining Stimulus Controllers with Twig Filter
Source: https://context7.com/symfony/stimulus-bundle/llms.txt
Use the `stimulus_controller` Twig filter to chain multiple controllers onto a single element. This merges `data-controller` attributes and their associated values.
```twig
Search
{#
→
Search
#}
```
--------------------------------
### Retrieve Stimulus Attributes in Twig
Source: https://github.com/symfony/stimulus-bundle/blob/3.x/doc/index.rst
Use the `stimulus_target` Twig function to retrieve generated attributes for Stimulus controllers, useful for form elements.
```twig
{{ form_row(form.password, { attr: stimulus_target('hello-controller', 'myTarget').toArray() }) }}
```
--------------------------------
### Stimulus Action with Explicit Event in Twig
Source: https://context7.com/symfony/stimulus-bundle/llms.txt
Specify an explicit DOM event name (e.g., 'input') when defining a Stimulus action using the `stimulus_action` function.
```twig
{# → #}
```
--------------------------------
### stimulus_target() - Twig Function
Source: https://context7.com/symfony/stimulus-bundle/llms.txt
Renders a `data-{controller}-target` attribute to register an element as a named target within a Stimulus controller. It supports single targets, multiple target names, and can be used with `.toArray()` for form rows.
```APIDOC
## `stimulus_target()` — Twig Function
Renders a `data-{controller}-target` attribute that registers the element as a named target inside a Stimulus controller.
```twig
{# Single target #}
{# →
#}
{# Multiple target names in one call #}
{# →
#}
{# Use .toArray() in a form row #}
{{ form_row(form.email, {
attr: stimulus_target('validation', 'emailField').toArray()
}) }}
```
```
=== COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.