TripWired TripWired - 2 months ago 12
Groovy Question

Inline if statement in grails

Is there a way in Grails to do conditionals inline on an HTML attribute, for example:

<div class="${if(sec.isLoggedIn()) loggedInClass}">

I'm trying to add a class to certain elements if the user is logged in.


This might work for you:

<div class="${(sec.isLoggedIn()?loggedInClass:null)}">

Or Try this:

<div class="${(sec.isLoggedIn()?'loggedInClass':'null')}">