Reputation: 6802
Using Grails 3.0.9
I tried setting up a custom tag, but I can't get it to work. I created the following groovy file in grails-app/taglib: BeanFormGenerator.groovy
class BeanFormGenerator {
def renderList = { attrs, body ->
// reads the 'values' attribute from the attributes list
def list = attrs.values
// iterates and renders list values
list.each {
// uses the implicit 'out' variable to append content to the response
out << "<span class=\"element\"> ${it} </span>"
}
}
}
And I have this call in a gsp file:
<g:renderList values="[1, 2, 3]">check check</g:renderList>
I get the error:
Tag [renderList] does not exist. No tag library found for namespace: g
I tried creating a custom namespace inside of BeanFormGenerator:
static namespace = "beanform"
But this just caused to be treated as markup. What am I doing wrong? The documentation makes it seem like this should be all there is to it. I'm running this inside of IntelliJ community edition if that makes a difference.
Upvotes: 0
Views: 1195
Reputation: 50245
Quite simply, to create a tag library create a Groovy class that ends with the convention TagLib and place it within the grails-app/taglib directory
grails.github.io/grails-doc/3.0.9/guide/single.html#taglibs
Upvotes: 1