I have defined a taglib like this:
class FooTagLib {
static namespace = "foo"
def bar = { attrs, body ->
out << render(template: "/taglib/foo/bar", model: [body: body])
}
}
The body closure takes two parameters, baz and qux, why can't I do this in my /taglib/foo/_bar.gsp:
${body(baz: 'Hello', qux: 'world!')}
?
This is how I use this tag in my gsp views:
<foo:bar>
${baz} ${qux}
</foo:bar
It prints the content of the body, but the parameters are all null
:
null null
Is this a bug or is there something I am doing wrong?
Inside the taglib you never specify any params, it is not done automatically, because the taglib does not know the names of the map keys. You must specify the map keys and values in the model.
class FooTagLib {
static namespace = "foo"
def bar = { attrs, body ->
def s = body()
def tokens = s.tokenize()
out << render(template: "/taglib/foo/bar", model: [body: [baz:tokens[0], qux:tokens[1]] ])
}
}
Maybe the body-tokenize is not really what you should be doing, but it was just to make things clear.
It would be easier for you to use attrs
, instead of building the body closure with params.