Plugins You can find out about all the publicly available Grails plugins.

Active Link Tag Plugin

2 votes
compile "org.grails.plugins:active-link:1.0"

 Documentation  Source  Issues


This plugin is a wrapper over g:link tag. Plugin providing g:activeLink tag which will add additional css class for g:link according specified condition. It is a translation of RoR "active_link_to".


grails install-plugin active-link



Easily mark g:link with extra css class which mean what link is active. Helpful if you are using navs components of bootstrap or foundation.



When forwardURI is '/books'
<g:activeLink controller="books" wrapper="li">Books</g:activeLink>
<li class="active"><a href="/books">Books</a></li>

More examples

<g:activeLink controller="books" class="btn">Books</g:activeLink>
<g:activeLink controller="books" class="btn" wrapper="li">Books</g:activeLink>
<g:activeLink controller="books" class="btn" wrapper="li" activeClass="current">Books</g:activeLink>
<g:activeLink controller="manage" condition="[controller: ['books','authors']]">Manage</g:activeLink>
<g:activeLink controller="books" condition="${~/book/}">Books</g:activeLink>
<a href="/books" class="btn active>Books</a>
<li class="active"><a href="/books" class="btn">Books</a></li>
<li class="current"><a href="/books" class="btn">Books</a></li>
<li class="active"><a href="/manage">Manage</a></li>
<a href="/books" class="active>Books</a>


activeClass (optional) - the name of css class for active link (By default: "active")

wrapper (optional) - using for wrapping link in another tag. If link active the css class will be applied for wrapper.

condition (optional) - custom rule for marking link as active.

Condition allowed values

  • Boolean
<g:activeLink controller="test" condition="${true}">Test</g:activeLink> == 
	"<a href="/test" class="active">Test</a>"
  • RegExp
request.forwardURI == "/test/page/1"
<g:activeLink controller="demo" condition="${~/(w)+/(w)+/(d)+/}">Test</g:activeLink> == 
	"<a href="/demo" class="active">Test</a>"
  • Map
<g:activeLink controller="demo" condition="[controller: 'test', action: 'list']">Test</g:activeLink>
<g:activeLink controller="demo" condition="[controller: ['test', 'demo']]">Test</g:activeLink>
  • "exclude" will add active class if link href uri is equal to request.forward_URI excluding GET params.
request.forwardURI == "/test/list?page=1"
<g:activeLink controller="test" action="list" params="[page: 2]" condition="exclude">Test</g:activeLink> == 
"<a href="/test/list?page=2" class="active">Test</a>"
  • "include" take into consideration GET params.
request.forwardURI == "/test/list?page=1"
<g:activeLink controller="test" action="list" params="[page: 2]" condition="include">Test</g:activeLink> == 
"<a href="/test/list?page=2">Test</a>"

About g:link attributes you can read in documentation.