简体   繁体   中英

Call Grails 2 r:require module from a taglib

Having a taglib that uses an external js library to show user notification. Since calling this taglib in many views, I'm wondering how to require the library js module directly from the tag, without doing it from each gsp view.

Currently I'm using this code in the gsp file:

<g:require modules="pnotify"/>

And below in the taglib source code:

class MyTagLib {

    static namespace = "my"

    def myHtmlWithNotifications = { attrs ->
        out << "<table>"
        // ...
        out << "</table>"
    }
}

Just call the require module from the taglib in this way:

class MyTagLib {

    static namespace = "my"

    def myHtmlWithNotifications = { attrs ->
        out << r.require([modules: "pnotify"])
        out << "<table>"
        // ...
        out << "</table>"
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM