TripWired TripWired - 24 days ago 7
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.

Answer

This might work for you:

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

Or Try this:

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