ubundude
ubundude

Reputation: 89

Grails g:if tag test request URI

I am somewhat new to Grails and not sure how to accomplish this. I am dealing with a navigation list in my gsp file. What I am trying to do is test whether the request URI starts with a given string and if so, set the list item to active. The way I had seen to do this in the past was like this:

<li
    <g:if test="${request.getRequestURI().startsWith("/packageName/domainController")}">
        class="active"
    </g:if>
>
<g:link controller="sectionHome" params="[section: section]" >
    Class Home
</g:link>
</li>

This model doesn't work. Not sure if there is a tag out of order, or if there is a new method I just can't find. Thanks in advance for any help.

Upvotes: 0

Views: 621

Answers (1)

Mimo
Mimo

Reputation: 6075

You have in your gsp to ${controllerName} and ${actionName} so you can do something like:

<li
    <g:if test="${controllerName == 'MyController'}">
        class="active"
    </g:if>
>

Hope that helps!

Upvotes: 0

Related Questions