Get the environment name in a Twig template with Symfony2
SymfonyTwigSymfony Problem Overview
Is there a way to get the name of the current environment in a Twig template? I'd like to set some CSS style values depending on it.
Symfony Solutions
Solution 1 - Symfony
http://symfony.com/doc/current/templating/app_variable.html:
<p>Application Environment: {{ app.environment }}</p>
Solution 2 - Symfony
Use
app.environment
e.g.
{% extends app.environment == 'dev' ? "::dev_layout.html.twig" : "::layout.html.twig" %}
Solution 3 - Symfony
Or you can use
app.debug
This returns true if debug is enabled. This is usually the case in the dev environment, however debug can be enabled in any of the environments... prod, test, dev, etc....