Search code examples
grailsdynamicgsptaglib

Calling custom tagLib inside another custom tagLib dynamically


I have made two custom tagLibs, namely tabContainer and tab.

def tabContainer = { attrs, body ->
    println("body: "+body())
    out << '<div class="tab-content">' << body() << '</div>'
}

and

def tab = { attrs, body ->
    out << '<div class="tab-pane '+${attrs.active == "true" ? "active" : ""}+'" id="'+attrs.id+'">' << body() << '</div>'
}

Now I want to insert the tab inside tabContainer as many times the user specifies inside GSP page like-

<myUI:tabContainer>
    <myUI:tab id="hello1">Hello1 contents</myUI:tab>
    <myUI:tab id="hello2" active="true">Hello2 contents</myUI:tab>
</myUI:tabContainer>

Now if I do that then comes the following error-

Error processing GroovyPageView: Error executing tag <myUI:tabContainer>: Error executing tag <myUI:tab>: No signature of method: myui.myUITagLib.$() is applicable for argument types: (myui.myUITagLib$_closure14_closure15) values: [myui.myUITagLib$_closure14_closure15@2090a569]

Need: Any number of tab can be passed inside tabcontainer as passed by the user on a GSP page.


Solution

  • Change your tab tag like this .It working for me.

    out << '<div class="tab-pane ' + (attrs.active == "true" ? 'active' : '') + '" id="' + attrs.id + '">' << body() << '</div>'