TripWired TripWired - 1 year ago 152
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 Source

This might work for you:

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

Or Try this:

<div class="${(sec.isLoggedIn()?'loggedInClass':'null')}">
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download