Abdennour TOUMI
Abdennour TOUMI

Reputation: 93491

g:if inside g:link does not work

The question title is enough to explain excepting the attempts that i try :

Attempt1 :

<g:link controller="staff" action="all" <g:if test="${actionName=='all' }">class="active"</g:if> >Overview</g:link>

Error Message

Error 500

Class :org.codehaus.groovy.grails.web.taglib.exceptions.GrailsTagException Message Grails tag [g:link] was not closed


Attempt2 :

<g:link controller="staff" action="all" class="<g:if test="${actionName=='all' }">active</g:if>" >Overview</g:link>

Error Message

Error 500 Class org.codehaus.groovy.grails.web.taglib.exceptions.GrailsTagException Message Attribute value must be quoted (controller="staff" action="all" class="

How to do a branching to decide if an element has css class X or not ?

X(in this example)= active

Upvotes: 2

Views: 722

Answers (1)

ABC
ABC

Reputation: 4373

I think It will be sufficient if you will use ternary operator e.g:

<g:link controller="staff" action="all"  class="${actionName == 'all' ? 'active' : ''}">
    Overview
</g:link>

Upvotes: 5

Related Questions