15

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 _____

user111544
  • 201
  • 2
  • 5

3 Answers3

25

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
  • 1,573
  • 2
  • 10
  • 8
4

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" }
user111544
  • 201
  • 2
  • 5
0

For the sake of completeness, since it's not mentioned in the docs: if you are calling the tags (as metod calls) inside your own taglib, you can use the closure to output any other content (using out <<) inside the outer tag. For example:

out << g.form(method: "post", controller: "login") {
    out << "Name: " << g.textField(name: "name") << "<br>"
    out << "Password: " << g.passwordField(name: "password") << "<br>"
    out << g.submitButton(name: "login")
}
Tobia
  • 17,856
  • 6
  • 74
  • 93