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 !
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 %}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With