103

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.

GergelyPolonkai
  • 6,230
  • 6
  • 35
  • 69

3 Answers3

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

Chris
  • 6,302
  • 1
  • 27
  • 54
Sfblaauw
  • 1,556
  • 18
  • 21