Steve is a DZone MVB and is not an employee of DZone and has posted 4 posts at DZone. View Full User Profile

Detecting the Grails Environment in a GSP

03.26.2011
| 10576 views |
  • submit to reddit
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

References
Published at DZone with permission of Steve Good, author and DZone MVB. (source)

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)

Tags: