Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

<g:if> logical or condition

Tags:

grails

gsp

In grails gsp, instead of

<g:if env="development">
     <h1> xyz </h1>
</g:if>
<g:if env="production">
     <h1> xyz </h1>
</g:if>

is it possible to write logical or condition in <g:if> to combine the two conditions

for example

<g:if test="env='production'"||"env='devlopment'">
    <h1> xyz </h1>
</g:if>

What's the right way of doing that?

like image 950
johnsam Avatar asked Sep 08 '25 15:09

johnsam


2 Answers

Just for the sake of DRYness:

<%@ page import="grails.util.Environment" %> 
<g:if test="${Environment.current in 
                [Environment.PRODUCTION, Environment.DEVELOPMENT]}">
    <h1>xyz</h1>
</g:if>
like image 188
dmahapatro Avatar answered Sep 10 '25 05:09

dmahapatro


I found the following would work.

<g:if test="${grails.util.Environment.current.name.equals('development') ||                      
              grails.util.Environment.current.name.equals('production')}">
        <h1>xyz</h1>
</g:if>
like image 43
johnsam Avatar answered Sep 10 '25 05:09

johnsam