I'm using symfony 2.8 and twig 1.2, I was wondering if there is a way to set a global variable for twig templates, I would hate to go into each and every twig file and change the value, if there was a central place where I can set the variable value and use it in any of the twig files regardless of the directories they are in that would be great.
As of now I'm defining key values in parameters.yml
file
parameters:
client_name: 'naruto uzumaki'
And then inside the controller I have
<?php
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
class MyController extends Controller
{
public function editAction()
{
$var = $this->container->getParameter('client_name');
return $this->render("UserBundle:edit:edit.html.twig", array('var' => $var));
}
}
Then displaying it inside twig,
<h1>Hello, {{ var }}</h1>
I would like to avoid calling the service container in the controller and directly access client_name
value in the twig file, any help would be appreciated