On newer versions of Symfony2 (using a parameters.yml
instead of parameters.ini
), you can store objects or arrays instead of key-value pairs, so you can manage your globals this way:
config.yml (edited only once):
# app/config/config.yml
twig:
globals:
project: %project%
parameters.yml:
# app/config/parameters.yml
project:
name: myproject.com
version: 1.1.42
And then in a twig file, you can use {{ project.version }}
or {{ project.name }}
.
Note: I personally dislike adding things to app
, just because that's the Symfony's variable and I don't know what will be stored there in the future.