0
votes

I am writing my own CMS using Symfony 3 right now and i have problem with include the same variables in all controllers.

For example:

I want render logo which i have just upload in my admin panel so i keep URL to it in database and fetch with other data like meta (site descryption, site title etc.) in controller - passing it as array and call in base.html.twig

However base.html.twig extends all other twig templates which i use in controllers so i must fetch it in all of them.

Is there some nice solution for my problem ?

1
So are you using: {% extends 'base.html.twig' %} in all your Twig templates? You haven't actually posted any of your code. Welcome to stackoverflow!Alvin Bunk
Thank you. I have just found solution. I can add some global variables to twig using addGlobal() method.OceanFire

1 Answers

0
votes

Posting an answer based on your comment.

Use addGlobal() method in your base controller like so:

$this->get('twig')->addGlobal('variable', $variable);

Where $variable is the global variable you need.