1

Problem: Include analytic JS code in production, but not in staging or development.

Attempted to detect production environment with:

{if "{site_url}" == "http://www.example.com/"}

... but that's not evaluating as true; attempted to debug to get correct value of {site_url}, but, the value I'm using looks to be correct (copied/pasted to be sure).

<!-- {site_url} --> outputs <!-- http://www.example.com/ -->

Is this a parse order issue, or is there sometime obvious I'm missing in my pre-coffee state this morning?

If it's parse order, how do you go about doing conditionals on the environment within your templates if not with {site_url}?

Note: I'll actually respond if you take the time to assist, and, I'll mark the correct answer as answered ;-)

5

Or set a $env_global['myjs'] in the config.prod.php with the analytics code ID number and leave that var blank in the config.dev.php then just {myjs} in the template and it only outputs the ID in production.

2
  • Interesting; have been doing this a long time, didn't know about $env_globals; thanks! – Nick Benson Jan 13 '14 at 13:31
  • 1
    Thanks for getting me pointed in the right direction! For future reference to anyone else who might stumble across this, the concept is fleshed out in more detail here: expressionengine.stackexchange.com/questions/9798 – Nick Benson Jan 13 '14 at 20:32
0

{if site_url == "www.example.com"} it's true! {/if}

I think your syntax is incorrect. Notice that the site variable does not have {} or uses quotes. That's no correct in the EE syntax.

http://ellislab.com/expressionengine/user-guide/templates/globals/conditionals.html

1
  • Tried with and without quotes, made no difference. – Nick Benson Jan 13 '14 at 13:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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