I'm developing a site with Git and Master Config, and up until yesterday I was forcing users to log-in to view the site on the development server with this code in my document head template:

{if logged_out}

But now the site has been launched to production, I have to remove that code and template group. But since everything is synced up using Git, the development environment won't be password protected either.

I'd prefer to use EE's built-in login system over say a .htpasswd file if possible. I figure I can .gitignore the tmp template group so it only exists on development. Is there a Master Config variable I can use to only parse the logged_out conditional in the development environment? Like:

{if ENV == 'dev'}
    {if logged_out}

5 Answers 5


Version 1.1.1 of the Master Config added two global variables by default. Here's a sample of use:

{if global:env == 'dev'}
    {if logged_out}

An alternate approach without nesting conditionals:

{if global:env == 'dev' && logged_out}

If you are using a version before 1.1.1 you can just add that section of code to your current config.master.php file.

I figure I can .gitignore the tmp template group so it only exists on development.

I'd recommend adding a conditional to any template in that group. The conditional would redirect the user if they aren't in the desired environment. It's a bigger process depending on how many templates you're running in the group, but allows you to track the template(s) and their changes. It also means your other contributors will have these files.


 {if global:env != 'dev'}{redirect='/'}{/if}
  • That's a great suggestion regarding the template group, I think I'll do that.
    – kmgdev
    Commented Jan 15, 2013 at 19:37

Jason Siffring at Surprise Highway posted an article on how to do this with .htaccess. Unfortunately it requires a .htpasswd file, which it looks like you're trying to avoid.

Here's the link in case it's useful: http://surprisehighway.com/article/how-to-password-protect-development-and-staging-sites-with-htaccess


The main Master Config file has global variables configured that you can use:

From line 253:

$master_global = array(
    'global:env' => ENV,
    'global:env_full' => ENV_FULL

The variables for each environment are set in the config.env.php file.

{global:env} will get you "prod, stage, dev or local" and {global:env_full} will get you "Production, Staging, Development or Local".

These are global variables you can access in your templates.

So this conditional will get you what you need:

{if "{global:env}" != 'dev'}{redirect='/'}{/if}

I'd set a global variable in the config.php file:

$assign_to_config['global_vars']['ENV'] == 'dev';  

Then use this in your template:

{if "{ENV}" == 'dev'}

  • Do you know how I'd adapt that to work with Master Config?
    – kmgdev
    Commented Jan 15, 2013 at 18:48
  • I just edited my answer. A global variable already exists for you to use in Master Config.
    – Anna_MediaGirl
    Commented Jan 15, 2013 at 23:08

I would suggest putting site offline (via EE preferences or config file) during development and using Smart Switch to allow limited access


What about using EE's built-in template permissions? It's located under the "access" tab when editing a template. Way easier IMHO than writing a bunch of conditionals into your templates and then having to rip them out when going live. Here's an example:

enter image description here

I would link to the page in EllisLab's docs, but the EE docs are down right now.

  • Docs are back up. Here's the link, hope this helps you out.
    – vibe9
    Commented Jan 16, 2013 at 23:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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