user111544
user111544

Reputation: 201

Grails link taglib use outside of GSP

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 _____

Upvotes: 15

Views: 8019

Answers (3)

Tobia
Tobia

Reputation: 18811

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")
}

Upvotes: 0

Zim
Zim

Reputation: 1643

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"}

Upvotes: 25

user111544
user111544

Reputation: 201

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" }

Upvotes: 4

Related Questions