简体   繁体   中英

grails 4 call a namespaced taglib from another taglib

How can I access a taglib wwith a different namespace from another taglib in grails 4? I can't seem to cross call.

Here's an example

 class MyLibTagLib{

  static namespace="myLib"

  def fancy={attrs->
      ....
  }
}

import app.lib.MyLibTagLib
class CallerTagLib{

  //in the default 'g' namespace

  //def myLib //injection fails

  def fancyText={attrs->
      //fails
      out << myLib.fancy(attrs)
      //also fails
      grailsApplication.mainContext.getBean('app.lib.MyLibTagLib')
  }
}

I cannot reproduce the problematic behavior that you describe. See the project at https://github.com/jeffbrown/tagquestion .

https://github.com/jeffbrown/tagquestion/blob/9a389f957c8327d071e55a131b9c8a83663a6f3e/grails-app/taglib/demo/MyLibTagLib.groovy

package demo

class MyLibTagLib {
    static namespace="myLib"

    def fancy={attrs->
        out << 'Something Fancy'
    }
}

https://github.com/jeffbrown/tagquestion/blob/9a389f957c8327d071e55a131b9c8a83663a6f3e/grails-app/taglib/demo/CallerTagLib.groovy

package demo

class CallerTagLib {

    def fancyText = { attrs ->
        out << myLib.fancy(attrs)
    }
}

The main index.gsp at https://github.com/jeffbrown/tagquestion/blob/9a389f957c8327d071e55a131b9c8a83663a6f3e/grails-app/views/index.gsp#L56 invokes <g:fancyText/> and that works.

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