Download the PHP package hello-sebastian/hello-stimulus-bundle without Composer
On this page you can find all versions of the php package hello-sebastian/hello-stimulus-bundle. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download hello-sebastian/hello-stimulus-bundle
More information about hello-sebastian/hello-stimulus-bundle
Files in hello-sebastian/hello-stimulus-bundle
Package hello-stimulus-bundle
Short Description Symfony Bundle with Stimulus.js Helper functions
License MIT
Informations about the package hello-stimulus-bundle
HelloStimulusBundle
This Bundle provides Twig and Symfony form helper functions for Stimulus.js.
Overview
- Features
- Installation
- Twig helper functions
- Form helper functions
Features
- Twig helper functions
- Symfony Forms helper functions
Installation
Step 1: Download the Bundle
Open a command console, enter your project directory and execute the following command to download this bundle:
Step 2: Enable the Bundle (without flex)
Then, enable the bundle by adding it to the list of registered bundles in the config/bundles.php
file of your project:
Twig helper functions
hello_stimulus_controller(controllerName, values = [])
Render value controller attribute. Optional with values.
Parameters
controllerName: name of the controller
values: array of stimulus values (optional)
Examples
is rendered to
You can use two ways to specify the controller:
Assuming the controller is located at assets/controllers/user/user_form_controller.js
-
the "HTML" stimulus type
- the "JavaScript" type
Both variants give the same result.
hello_stimulus_target(controllerName, target)
Render value target attribute.
Parameters
controllerName: name of controller for this target
target: name of the target attribute
Examples
is rendered to
hello_stimulus_action(controllerName, event, method)
Render action data attribute.
Parameters
controllerName: name of controller for this action
event: DOM event to listen for
method: name of the JavaScript method inside the controller class
Examples
is rendered to
hello_stimulus_value(controllerName, name, value)
Render value data attribute.
Parameters
controllerName: name of controller for this value
name: name of this value
value: value of this value
Examples
is rendered to
Form helper functions
In Symfony Forms it is helpful to pass attributes of stimulus directly to the types. For this purpose, this bundle provides a helper class with two methods (target()
and value()
).
Full example of StimulusFormHelper
StimulusFormHelper API
__construct(controllerName, defaultEvent = "click")
Paramters
controllerName: name (and location) of the JavaScript controller class
defaultEvent: (optional): default DOM event to listen for (default is the "click" event)
Usage
You can use two ways to specify the controller:
Assuming the controller is located at assets/controllers/user/user_form_controller.js
-
the "HTML" stimulus type
- the "JavaScript" type
Both variants give the same result.
target(target)
Parameters
target: name of target property inside stimulus controller
Returns
Usage
action(method, event = null)
Parameters
method: name of JavaScript method inside stimulus controller
event: (optional) DOM event to listen for (if null, default event from constructor is taken)
Returns
Usage
Example
action
and traget
return an array. If you want to use both inside the same attr
, you can use array_merge()
.
All versions of hello-stimulus-bundle with dependencies
sensio/framework-extra-bundle Version ^5.1
symfony/twig-bundle Version ^4.4|^5.0
symfony/form Version ^4.4|^5.0