I wrote a taglib which executes some logic and renders some data weaved into HTML. When I use the taglib in a view, the taglib expects to find the template in a relative subfolder of the view. Is there a way in which I can make the taglib pick up the template from a common folder like the layouts/ folder in view. This is how the taglib code looks:
class IconifiedTextTagLib {
def renderIconText = { attrs, body ->
//some processing logic to generate the modelMap
out << render(template:"taglibTemplates/iconText", model:modelMap)
}
}
When I use the <g:renderIconText />
tag in say a controller named A, then it expects the taglibTemplates/iconText to be present in the views/A/ folder. This is a problem because I need to be able to use it from multiple controllers. I need a way to put the templates in a folder like layouts/ so that it can be used in all the views. Any thoughts on how I can do this?
Put template into views/taglibTemplates/
and try:
out << render(template:"/taglibTemplates/iconText", model:modelMap)
or into `views/A/', and
out << render(template:"/A/iconText", model:modelMap)
on grails 2.3.8 I had to use as such
make sure the template filename starts with underscore
_mytemplate.gsp
in your tag library class
out << g.render(template: '/taglibTemplates/mytemplate')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With