views:

1191

answers:

2

I'm trying to use the taglib call there's attribute parameters, but also the stuff inside the tag itself which the link taglib uses. I can't find the attribute to pass in to a g.link() call to have it render the text of the link. I've tried 'body' and 'link' and 'text' and 'linkText' already - none of those work.

I'm expecting to be able to call

g.link(action:"foo", controller:"bar", _____:"text of the link here")

but don't know what to put in _

+1  A: 

There is no parameter to pass in (for better or for worse).

To get the text in the link, you pass it as a closure.

g.link(action:"foo", controller:"bar") { "text of the link here" }
+3  A: 

Usually you do it like this:

g.link(action:"foo", controller:"bar", "text of the link here")

The link text doesn't need to be the last parameter, it may appear anywhere:

g.link("text of the link here", action:"foo", controller:"bar")

.

Usage with closure:

Instead of the string you can use a closure which returns a string:

g.link(action:"foo", controller:"bar", {"text of the link here"})

And, as with any groovy closure which is the last parameter for a method call, you can put it after the closing parentheses:

g.link(action:"foo", controller:"bar") {"text of the link here"}
Zim
The docs don't reference this at all, but do show a closure. Docs probably need updating.
I updated the answer to explain that.
Zim