Loading...

February 27, 2009

Conditional display of text in GSP file in Grails

Grails contains so many useful features I encounter one (at least) each day. Today I wanted to add Google Analytics code to my site. But the Javascript code only is necessarry in the production environment. Well Grails makes it so easy:

<g:if env="production">
...JS code for Google Analytics...
</g:if>

The if tag has a env attribute. And if the Grails applications run in the specified enviornment, then the code in the tag is added to the page.