Take the 2-minute tour ×
Craft CMS Stack Exchange is a question and answer site for administrators, end users, developers and designers for Craft CMS. It's 100% free, no registration required.

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 %}

Thanks!

share|improve this question

1 Answer 1

up vote 8 down vote accepted

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 %}
share|improve this answer
    
You can also define totally custom variables in the same way (e.g. 'cache' => false{% if craft.config.cache %}) –  carlcs Aug 12 at 10:32

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.