Search code examples
grailsgsp

grails: is conditional markup in a gsp page possible just using ${}


Grails of course has the built in "if" and "else" tag, e.g.

 <g:if test="${name == 'Fred'}">
     Hello Fred, welcome back from your trip!
 </g:if>
 <g:else>
     Hello ${name}
 </g:else>

Is it possible to so something like this purely using the ${} capability on a gsp page? Not using the

   <g:if> and 
   <g:else>

tags?


Solution

  • Yes, e.g. like this:

    Hello ${name}${name == "Fred" ? ", welcome back from your trip!" : ""}