Search code examples
grailsgsp

How to call taglib method inside a column in list view?


I have a taglib method written in taglib.groovy. I want to use that method in one of the columns inside my list view of objects.

How should I approach that?


Solution

  • You can call it like any other taglib method:

    <g:myTag />
    

    Or if you're passing attributes:

    <g:myTag attr1="Attr1" attr2="Attr2" />
    

    Unless you've used a different namespace in the taglib then use that in the call:

    <myNameSpace:myTag attr1="Attr1" attr2="Attr2" />
    

    To call from a controller using the g namespace:

    g.myTag( attr1: 'Attr1', attr2: 'Attr2' )
    

    Or for a custom tag lib using Grails 3:

    myNameSpace.myTag( attr1: 'Attr1', attr2: 'Attr2' )
    

    Another way to access:

    def myTagLib = grailsApplication.mainContext.getBean( 'com.MyTagLib' )
    myTagLib.myTag( attr1: 'Attr1', attr2: 'Attr2' )