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.
3 Answers
http://symfony.com/doc/current/templating/app_variable.html:
<p>Application Environment: {{ app.environment }}</p>
-
It slipped my eye, sorry about that... Thank you for pointing out! Apr 17, 2012 at 18:14
-
2It would have been helpful to provide the actual answer with the link.– afilinaJan 14, 2014 at 22:36
Use
app.environment
e.g.
{% extends app.environment == 'dev' ? "::dev_layout.html.twig" : "::layout.html.twig" %}
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. Jul 30, 2013 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.– afilinaJan 14, 2014 at 22:38
-
2
-
2
-
1Although this is not the proper answer to the OP, this is more useful Feb 5, 2018 at 14:54