hospect / php-vars-to-js-bundle
Transformation of PHP vars to JS for Symfony2 with Twig
Installs: 30 895
Dependents: 0
Suggesters: 0
Security: 0
Stars: 9
Watchers: 2
Forks: 1
Open Issues: 0
Type:symfony-bundle
Requires
- laracasts/utilities: ~2.0
- symfony/framework-bundle: >=2.3
- twig/twig: >=1.16
Requires (Dev)
- phpspec/phpspec: ~2.1@dev
This package is not auto-updated.
Last update: 2025-03-29 20:08:30 UTC
README
Description
Bundle allows you to avoid horrible statements in Twig templates while setting JS variables from PHP ones, like:
var someJsVar = '{{ somePhpVar }}', anotherJsVar = '{{ anotherPhpVar }}';
Installation
Simply require it with composer:
composer require hospect/php-vars-to-js-bundle
And register in your AppKernel.php
:
public function registerBundles() { $bundles = array( // some other bundles... new \Hospect\PhpVarsToJsBundle\HospectPhpToJsBundle(), ); return $bundles; }
Usage
In your controller call:
$this->get('php_to_js')->put([ 'someJsVar' => $somePhpVar, // more vars here... ]);
Then in Twig template (probably that will be useful to move it to layout):
<script> {{ initPhpVars() }} </script>