96
votes

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

3 Answers

172
votes
42
votes

Use

app.environment

e.g.

{% extends app.environment == 'dev' ? "::dev_layout.html.twig" : "::layout.html.twig" %}
22
votes

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