I need to define a global variable in symfony2 and then, use it in several php template.
I found in documentation how to use in twig templates, but I need how to define and use in php template.
Thanks.
I need to define a global variable in symfony2 and then, use it in several php template.
I found in documentation how to use in twig templates, but I need how to define and use in php template.
Thanks.
You can define global variable in twig template like:
# app/config/config.yml
twig:
# ...
globals:
ga_tracking: UA-xxxxx-x
Or it in PHP template like:
// app/config/config.php
$container->loadFromExtension('twig', array(
// ...
'globals' => array(
'ga_tracking' => 'UA-xxxxx-x',
),
));
And then use it in twig:
<p>The google tracking code is: {{ ga_tracking }}</p>
or in PHP template:
<p>The google tracking code is: <?php echo $ga_tracking; ?></p>