Essentially, I’m trying to find a DRYer way to represent this code:
<li><g:link controller="ActivityDashboard" action="summary">Summary</g:link></li>
<li><g:link controller="ActivityDashboard" action="user_details">User Details</g:link></li>
<li><g:link controller="ActivityDashboard" action="groups_monitors">Groups & Monitors</g:link></li>
<li><g:link controller="ActivityDashboard" action="Top Content">Top Content</g:link></li>
<li><g:link controller="ActivityDashboard" action="embedded_components">Embedded Components</g:link></li>
<li><g:link controller="ActivityDashboard" action="customer_summary">Customer Summary</g:link></li>
As you can see, there is a lot of repetition so I created the a tag as the following:
def navLink = { attrs, body ->
out << "<li>"
out << "<g:link controller='ActivityDashboard' action='${attrs.action}'>${attrs.title}"
out << "</g:link></li>"
}
However, the output html is exactly:
<g:link action="summary" controller="ActivityDashboard">Summary</g:link>
How can I get to render like:
<a href="/engagementlevels/activityDashboard/summary">Summary</a>
Bonus Points: Can I access the the actionName attribute of the page from a tag?
You need to use the g.link() version of the tag so that the GString parses it and renders the output like you want.