本质上,我正在尝试找到一种 DRYer 方法来表示此代码:
<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>
正如你所看到的,有很多重复,所以我创建了如下的 a 标签:
def navLink = { attrs, body ->
out << "<li>"
out << "<g:link controller='ActivityDashboard' action='${attrs.action}'>${attrs.title}"
out << "</g:link></li>"
}
但是,输出 html 正是:
<g:link action="summary" controller="ActivityDashboard">Summary</g:link>
我怎样才能像这样渲染:
<a href="/engagementlevels/activityDashboard/summary">Summary</a>
奖励积分:我可以从标签访问页面的 actionName 属性吗?