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.
Asked
Active
Viewed 5.8k times
3 Answers
183
http://symfony.com/doc/current/templating/app_variable.html:
<p>Application Environment: {{ app.environment }}</p>

Community
- 1
- 1

marka.thore
- 2,795
- 2
- 20
- 35
-
It slipped my eye, sorry about that... Thank you for pointing out! – GergelyPolonkai Apr 17 '12 at 18:14
-
2It would have been helpful to provide the actual answer with the link. – afilina Jan 14 '14 at 22:36
46
Use
app.environment
e.g.
{% extends app.environment == 'dev' ? "::dev_layout.html.twig" : "::layout.html.twig" %}

zerkms
- 249,484
- 69
- 436
- 539

Tac Tacelosky
- 3,165
- 3
- 27
- 28
24
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....
-
6app.debug returns true only when debugging is enabled. Although enabling debug mode in the production environment is generally a bad idea, it's not impossible it is turned on. – GergelyPolonkai Jul 30 '13 at 14:52
-
3Debug can be enabled or disabled for any environment. Also, there are more than just two environments possible (I usually use 3 or 4), so a boolean is of little help. – afilina Jan 14 '14 at 22:38
-
2
-
2
-
1Although this is not the proper answer to the OP, this is more useful – nicolallias Feb 05 '18 at 14:54