Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I read configuration settings from Symfony2 config.yml in twig template?

Tags:

twig

symfony

In controller i can read like this

$this->container->getParameter('test');

But how get this var "test" in my twig template?

like image 448
dim-dim Avatar asked Sep 30 '11 08:09

dim-dim


2 Answers

Depends what you need to get, my way of getting data from parameters.ini is:

config.yml

twig:
    globals: 
        google_maps_api_key: %google_maps_api_key% 

parameters.ini

[parameters]
    google_maps_api_key="authkey"

in template:

{{ google_maps_api_key }}

Hope it helps.

like image 156
BartłomiejNoszka Avatar answered Sep 18 '22 16:09

BartłomiejNoszka


Yes, you can create your own Twig extension, in this class you can override getGlobals() and return an array with your global variables.

Or you can create a Twig method in this extension param($value) to return the right parameter.

like image 43
Tom eBuildy Avatar answered Sep 21 '22 16:09

Tom eBuildy