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

前端 未结 2 1557
南笙
南笙 2021-02-05 13:45

In controller i can read like this

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

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

2条回答
  •  伪装坚强ぢ
    2021-02-05 14:07

    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.

提交回复
热议问题