I just begun to use Symfony, and I came from CodeIgniter. In this framwork you pass parameters to the view with an array called $data. So if you want to pass the same variables in each views of a controller, you simply instanciate the $data array in the consctrutor and add what ever you want.
For symfony it's a bit different, and I have imagine something to do the same. It's work great, but I ask myself if they doesn't exist a better way to do it. Or do I have to rethink the way I design my code to avoid this sort of things, for example add another twig layout for specify title in each route of the controller, but what if it's a parameter than I have to use for each render ?
First I define this function :
public function default_data(array $parameters):array{
$default_parameters = array(
'controller_name' => 'AdminController',
'navbar_title' => 'Suivis Satisfaction Utilisateurs',
);
return array_merge($default_parameters, $parameters);
}
Then I call render this way :
return $this->render(my_view.html.twig, $this->default_data(array('my_new_parameter' => 'new_data')));
Thanks for reading.