Answers.Body: <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>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-08-20T13:30:10.370Z
Answers.Text: This really helped with setting up some new custom environment variables outside of the default Craft 3 ones for a project. 
Answers.UserDisplayName: Jay
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-03-12T16:34:08.793Z
Answers.Text: 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.
Answers.UserDisplayName: mateostabio
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-09-18T08:33:38.440Z
Answers.Text: THank for this simple answer.
Answers.UserDisplayName: Sameera Thilakasiri
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-05-15T20:53:52.937Z
Answers.LastActivityDate: 2020-07-14T21:32:21.987Z
Answers.LastEditDate: 2020-07-14T21:32:21.987Z
Answers.UserDisplayName: kr37
Answers.Body: <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>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-12-02T00:05:01.273Z
Answers.LastActivityDate: 2015-12-02T00:05:01.273Z
Answers.UserDisplayName: kmgdev
Answers.Body: <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>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-03-25T19:06:26.747Z
Answers.LastActivityDate: 2021-03-25T19:06:26.747Z
Answers.UserDisplayName: Mage
Answers.Body: <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>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-08-12T10:32:36.590Z
Answers.Text: 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))
Answers.UserDisplayName: carlcs
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-03-30T14:35:50.600Z
Answers.Text: 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.
Answers.UserDisplayName: James Smith
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-10-09T06:26:48.600Z
Answers.Text: deprecated. now its `craft.app.config.general.devMode`
Answers.UserDisplayName: André Kelling
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-08-11T11:07:12.467Z
Answers.LastActivityDate: 2014-08-12T08:00:02.437Z
Answers.LastEditDate: 2014-08-12T08:00:02.437Z
Answers.UserDisplayName: Alec Ritson
Body: <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>
  
Tags: <templating><multi-environment><devmode>
Title: Access environment information in template
ThreadText: # 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](https://docs.craftcms.com/v3/config/environments.html).
  
  > **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.
  
  
  ---
  
  