<p>In Craft 3 you can get the env using the <code>getenv()</code> function:</p>
<pre><code>{% set env = getenv('ENVIRONMENT') %}

{% if env == 'dev' %}
    hello dev
{% else %}
    hello world
{% endif %}
</code></pre>
<p>Or via the app’s config service:</p>
<pre><code>{% set env = craft.app.config.env %}
</code></pre>
<p>There's a bit more information about the .env file in the docs for <a href="https://docs.craftcms.com/v3/config/environments.html" rel="noreferrer">Environmental Configuration</a>.</p>

CC BY-SA 4.0
2018-08-20T13:30:10.370Z
This really helped with setting up some new custom environment variables outside of the default Craft 3 ones for a project. 
Jay
CC BY-SA 4.0
2019-03-12T16:34:08.793Z
This worked wonders! Thanks. Very handy when you want to work off local files in dev, but need the absolute URL on the production site.
mateostabio
CC BY-SA 4.0
2019-09-18T08:33:38.440Z
THank for this simple answer.
Sameera Thilakasiri
CC BY-SA 4.0
2018-05-15T20:53:52.937Z
2020-07-14T21:32:21.987Z
2020-07-14T21:32:21.987Z
kr37
<p>You can set a custom "environment label" variable inside config/general.php:</p>

<pre><code>return array(
    // ALL ENVIRONMENTS
    '*' =&gt; array(
    ),
    // LOCAL
    'mysite.local' =&gt; array(
        'env' =&gt; 'local'
    ),
    // DEV
    'dev.mysite.com' =&gt; array(
        'env' =&gt; 'dev'
    ),
    // PROD
    'www.mysite.com' =&gt; array(
        'env' =&gt; 'prod'
    )
);
</code></pre>

<p>Then use the <code>craft.config</code> variable to output the <code>env</code> variable for the current environment:</p>

<pre><code>{% if craft.config.env == 'dev' %}
    hello dev
{% else %}
    hello world
{% endif %}
</code></pre>

CC BY-SA 3.0
2015-12-02T00:05:01.273Z
2015-12-02T00:05:01.273Z
kmgdev
<p>I know this is an old question, but just an update:</p>
<p>If you're on Craft CMS v3+, <code>craft.config.[setting-name]</code> has been deprecated.
Use <code>craft.app.config.general.[setting-name]</code> instead.</p>
<p>So if you wanted to check if you were in <code>dev</code> environment, you'd do <code>craft.app.config.general.devMode</code>, this returns a <code>boolean</code> value.</p>

CC BY-SA 4.0
2021-03-25T19:06:26.747Z
2021-03-25T19:06:26.747Z
Mage
<p>When developing locally on Craft you would most likely have <code>devMode =&gt; true</code> set in your config file and set to false for your production config.</p>

<p>app/config/general.php</p>

<pre><code>return array(
 'mydevdomain.dev' =&gt; array(
   'devMode' =&gt; true
 ),
 'mylivedomain.com' =&gt; array(
   'devMode' =&gt; false
 )
);
</code></pre>

<p>So you could test whether craft is in dev mode and respond to that:</p>

<pre><code>{% if craft.config.devMode %}
  You are in dev mode
{% else %}
  You are not in devmode
{% endif %}
</code></pre>

CC BY-SA 3.0
2014-08-12T10:32:36.590Z
You can also define totally custom variables in the same way (e.g. [`'cache' => false` → `{% if craft.config.cache %}`](http://craftcms.stackexchange.com/a/678/125))
carlcs
CC BY-SA 4.0
2019-03-30T14:35:50.600Z
In my opinion, this is a risky thing to do: it's not inconceivable that an inexperienced developer might be tempted to switch on dev mode in production to debug something 'guerilla' style, which could in turn trigger these conditionals unintentionally. Yes, that's a bad idea, but it could happen. Other devs might even switch on devMode in production by accident.
James Smith
CC BY-SA 4.0
2020-10-09T06:26:48.600Z
deprecated. now its `craft.app.config.general.devMode`
André Kelling
CC BY-SA 3.0
2014-08-11T11:07:12.467Z
2014-08-12T08:00:02.437Z
2014-08-12T08:00:02.437Z
Alec Ritson
<p>Is there a way to check what environment craft is running on - ie, dev or not dev - via the template.</p>

<p>For example:</p>

<pre><code>{%if env is 'dev'%}
    hello dev
{% else %}
   hello world
{% endif %}
</code></pre>

<templating><multi-environment><devmode>
Access environment information in template
# Access environment information in template

(Asked by: username_0 on 2014-08-11)

Is there a way to check what environment craft is running on - ie, dev or not dev - via the template.
For example:
{%if env is 'dev'%}
    hello dev
{% else %}
   hello world
{% endif %}

**Tags:** templating, multi-environment, devmode


---

## 4 answers

### Answer by username_7 on 2014-08-11. Score: 26 | Accepted answer

When developing locally on Craft you would most likely have devMode => true set in your config file and set to false for your production config.
app/config/general.php
return array(
 'mydevdomain.dev' => array(
   'devMode' => true
 ),
 'mylivedomain.com' => array(
   'devMode' => false
 )
);

So you could test whether craft is in dev mode and respond to that:
{% if craft.config.devMode %}
  You are in dev mode
{% else %}
  You are not in devmode
{% endif %}

> **Comments:**
> **username_8**: You can also define totally custom variables in the same way (e.g. [`'cache' => false` → `{% if craft.config.cache %}`](http://craftcms.stackexchange.com/a/678/125))  
> **username_9**: In my opinion, this is a risky thing to do: it's not inconceivable that an inexperienced developer might be tempted to switch on dev mode in production to debug something 'guerilla' style, which could in turn trigger these conditionals unintentionally. Yes, that's a bad idea, but it could happen. Other devs might even switch on devMode in production by accident.  
> **username_10**: deprecated. now its `craft.app.config.general.devMode`  

---

### Answer by username_1 on 2018-05-15. Score: 40

In Craft 3 you can get the env using the getenv() function:
{% set env = getenv('ENVIRONMENT') %}

{% if env == 'dev' %}
    hello dev
{% else %}
    hello world
{% endif %}

Or via the app’s config service:
{% set env = craft.app.config.env %}

There's a bit more information about the .env file in the docs for Environmental Configuration.

> **Comments:**
> **username_2**: This really helped with setting up some new custom environment variables outside of the default Craft 3 ones for a project.   
> **username_3**: This worked wonders! Thanks. Very handy when you want to work off local files in dev, but need the absolute URL on the production site.  
> **username_4**: THank for this simple answer.  

---

### Answer by username_5 on 2015-12-02. Score: 7

You can set a custom "environment label" variable inside config/general.php:
return array(
    // ALL ENVIRONMENTS
    '*' => array(
    ),
    // LOCAL
    'mysite.local' => array(
        'env' => 'local'
    ),
    // DEV
    'dev.mysite.com' => array(
        'env' => 'dev'
    ),
    // PROD
    'www.mysite.com' => array(
        'env' => 'prod'
    )
);

Then use the craft.config variable to output the env variable for the current environment:
{% if craft.config.env == 'dev' %}
    hello dev
{% else %}
    hello world
{% endif %}


---

### Answer by username_6 on 2021-03-25. Score: 4

I know this is an old question, but just an update:

If you're on Craft CMS v3+, `craft.config.[setting-name]` has been deprecated.
Use `craft.app.config.general.[setting-name]` instead.

So if you wanted to check if you were in `dev` environment, you'd do `craft.app.config.general.devMode`, this returns a `boolean` value.


---

