Get the environment name in a Twig template with Symfony2
http://symfony.com/doc/current/templating/app_variable.html:
<p>Application Environment: {{ app.environment }}</p>
Use
app.environment
e.g.
{% extends app.environment == 'dev' ? "::dev_layout.html.twig" : "::layout.html.twig" %}
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....