dev-master
9999999-dev http://github.com/fnash/FnashJsParamBundleSimple way to expose some symfony2 container parameters to javascript
MIT
The Requires
- php >=5.3.2
The Development Requires
by Fayez Naccache
js parameters
Simple way to expose some symfony2 container parameters to javascript
Simple way to expose some symfony2 container parameters to javascript, (*1)
``` bash $ php composer require fnash/js-param-bundle, (*2)
### Register bundle ```php <?php // AppKernel.php $bundles = [ // ... new Fnash\JsParamBundle\FnashJsParamBundle(), // ... ];
# app/routing.yml fnash_js_param_routing: resource: "@FnashJsParamBundle/Resources/config/routing.yml"
Given your parameters file, (*3)
# app/parameters.yml parameters: param1: value1 param2: value2 param3: value3 param4: value4
Add some parameters you want to expose in your javascript, (*4)
# app/config.yml fnash_js_param: expose: [param1, param2]
Be careful! Do not expose critical infos such as passwords etc.., (*5)
{% block javascripts %} ............. <script src="{{ path('fnash_js_param_js') }}"></script> ............. {% endblock %} </body> </html>
alert(window.FnashJsParam.param1); // value1 alert(window.FnashJsParam.param2); // value2
Simple way to expose some symfony2 container parameters to javascript
MIT
js parameters