Over a million developers have joined DZone.
Platinum Partner

Detecting the Grails Environment in a GSP

· Java Zone

Check out this 8-step guide to see how you can increase your productivity by skipping slow application redeploys and by implementing application profiling, as you code! Brought to you in partnership with ZeroTurnaround.

Last night I needed to make sure that my analytics tracking script was not running anywhere but in my production environment. After reading another blog post I came up with this simple GSP if block.

**** UPDATE ****

Thanks Burt for the comment pointing out that the original code I posted is actually deprecated and for pointing out a better way for testing environment.

According to the docs (and Burt), this is the correct way to test for environment in a GSP.

<g:if env="production">
<!-- Markup to include ONLY when in production -->
</g:if>

**** The code below is deprecated ****

<g:if test="${ grails.util.GrailsUtil.getEnvironment().equals(org.codehaus.groovy.grails.commons.GrailsApplication.ENV_PRODUCTION) }">
<!-- Markup to include ONLY when in production -->
</g:if>

Hope this helps others who are looking to do the same within their GSPs.

Detecting the Grails Environment in a GSP

The Java Zone is brought to you in partnership with ZeroTurnaround. Check out this 8-step guide to see how you can increase your productivity by skipping slow application redeploys and by implementing application profiling, as you code!

Topics:

Published at DZone with permission of Steve Good , DZone MVB .

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}