Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use different template layouts for dev and prod environment

Tags:

symfony

In symfony 2, I want a specific environment to use a specific layout and another one to use another layout.

What would be the best way to do that?

To further clarify, let's say I have a "prod_one" environment, and a "prod_two" environment. The prod_one environnment has to use some specific header in the html pages that are rendered, whereas the prod_two environment requires those headers not to be set.

Thank you !

like image 760
Saze Avatar asked Feb 16 '12 13:02

Saze


1 Answers

In Controller you can find out what environment is being used using kernel service' getEnvironment method:

$env = $this->get('kernel')->getEnvironment();
if ($env == "prod_one"){
    //$response->header->set(...);
    //return $this->render(...);
} else if ($env == "prod_two"){
  // ...
}

In twig: you can use the global twig variable - app.environment:

{% if app.environment == 'prod_one' %}
    {# Content for prod_one env #}
{% elseif app.environment == 'prod_two' %}
    {# Content for prod_two env #}
{% endif %}
like image 192
Molecular Man Avatar answered Sep 21 '22 23:09

Molecular Man