Search code examples
grailsgsp

Adding an id to a g:link in Grails


Is there anyway to add an id to a <g:link> tag?

In my .gsp file, I have the following code:

<g:link controller="application" action="index" id="my_id">My Link</g:link>

Grails produces the following HTML:

<a href="application/index">My Link</a>

According to the grails documentation, id is a valid attribute for <g:link>. So why is my id gone? Is there any workaround to tell grails to keep the id there?

Thanks!


Solution

  • Yes, it's possible. Use elementId instead of id. Like this:

    <g:link controller="application" action="index" elementId="my_id">My Link</g:link>

    You can read more about the attributes for the link tag in the documentation.