2017 © Pedro Peláez
 

symfony-bundle fnash-js-param-bundle

Simple way to expose some symfony2 container parameters to javascript

image

fnash/fnash-js-param-bundle

Simple way to expose some symfony2 container parameters to javascript

  • Tuesday, April 16, 2013
  • by fnash
  • Repository
  • 1 Watchers
  • 1 Stars
  • 35 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

FnashJsParamBundle

Simple way to expose some symfony2 container parameters to javascript, (*1)

Installation

Install

``` bash $ php composer require fnash/js-param-bundle, (*2)


### Register bundle ```php <?php // AppKernel.php $bundles = [ // ... new Fnash\JsParamBundle\FnashJsParamBundle(), // ... ];

Step 3: Import routing

# app/routing.yml

fnash_js_param_routing:
    resource: "@FnashJsParamBundle/Resources/config/routing.yml"

Step 4: Configure

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)

Step 5: Add javascript file to base template

    {% block javascripts %}
    .............
    <script src="{{ path('fnash_js_param_js') }}"></script>
    .............
    {% endblock %}
    </body>
</html>

Get your parameters from javascript

alert(window.FnashJsParam.param1); // value1
alert(window.FnashJsParam.param2); // value2

The Versions

16/04 2013

dev-master

9999999-dev http://github.com/fnash/FnashJsParamBundle

Simple way to expose some symfony2 container parameters to javascript

  Sources   Download

MIT

The Requires

  • php >=5.3.2

 

The Development Requires

by Fayez Naccache

js parameters