Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get the environment name in a Twig template with Symfony2

Tags:

twig

symfony

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.

like image 375
GergelyPolonkai Avatar asked Apr 17 '12 18:04

GergelyPolonkai


People also ask

How do I get the current URL in Twig?

You can get the current URL in Twig/Silex 2 like this: global. request. attributes. get('_route') .

How do you use variables in Twig?

In Twig templates variables can be accessed using double curly braces notation {{ variableName }} .

How do I comment in a Twig file?

To comment out one or more lines of code (or part of a line) use the the {# #} syntax. comment. Comments aren't just useful for writing notes about your code.


2 Answers

http://symfony.com/doc/current/templating/app_variable.html:

<p>Application Environment: {{ app.environment }}</p> 
like image 105
marka.thore Avatar answered Nov 13 '22 07:11

marka.thore


Use

app.environment 

e.g.

{% extends app.environment == 'dev' ? "::dev_layout.html.twig" : "::layout.html.twig" %} 
like image 21
Tac Tacelosky Avatar answered Nov 13 '22 08:11

Tac Tacelosky