Get the environment name in a Twig template with Symfony2

SymfonyTwig

Symfony 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....

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionGergelyPolonkaiView Question on Stackoverflow
Solution 1 - Symfonymarka.thoreView Answer on Stackoverflow
Solution 2 - SymfonyTac TaceloskyView Answer on Stackoverflow
Solution 3 - SymfonySfblaauwView Answer on Stackoverflow