0
votes

How could I get value from my config.yml file but not set as Twig global. for example:

mopa_boostrap:
    initializr:
        meta: ~

when I try

{{ mopa_bootstrap.initializr.meta }}

i got error that there is no such variable set in this template.

UPDATE As it is not possible to do without Twig Globals, I've done Twig extension which maps selected variables from config.yml to Twig Globals and make them available from template.

for whole implementation look here: https://github.com/nysander/MopaBootstrapBundle/commit/d36269184cfad6d8fd465d8b622f92a302dea104

2

2 Answers

1
votes

There is no way to do this. You have to set globals to use them in twig.

1
votes

Solution might be creating a twig extension with a function outputting what you want. Twig extension would be registered as a service and you could pass anything you want to it.