Timo Timo - 4 months ago 84
Twig Question

How to get config parameters in Symfony2 Twig Templates

I have a Symfony2 Twig template. I want to output the value of a config parameter in this twig template (a version number). Therefore I defined the config parameter like this:

parameters:
app.version: 0.1.0


I'm able to use this config parameter in Controllers but I have no clue how to get it in my Twig template.

Answer

Easily, you can define in your config file:

twig:
    globals:
        version: "0.1.0"

And access it in your template with

{{ version }}

Otherwise it must be a way with an Twig extension to expose your parameters.

Comments