Adapts Grails taglibs for use in the template engine. An adapter may be created like this:
def model = [:]
def tpl = template.make(model)
model.g = new TagLibAdapter(tpl)
model.g.registerTagLib(SimpleTagLib)
where SimpleTagLib is:
class SimpleTagLib {
def emoticon = { attrs, body ->
out << body() << (attrs.happy == 'true' ? " :-)" : " :-(")
}
}
Then it can be used inside a template like this:
g.emoticon(happy:'true') { 'Hi John' }
Performance-wise, it would be better to reimplement the taglib, but this makes it easier to reuse
existing code.
| Constructor and description |
|---|
TagLibAdapter
(BaseTemplate tpl) |
| Type Params | Return Type | Name and description |
|---|---|---|
|
Object |
methodMissing(String name, def args) |
|
void |
registerTagLib(Class tagLibClass) |
|
void |
registerTagLib(Object tagLib) |
Copyright © 2003-2017 The Apache Software Foundation. All rights reserved.