是否可以从 TagLib 中访问当前 Controller 实例?例如:
class FooTagLib {
static namespace = 'foo'
def msg = { attrs, body ->
// Can I get a reference to the current controller here?
}
}
我想这样做是因为我将一些数据存储在 Controller 的属性中并希望在 TagLib 中访问它。我意识到这可能听起来很奇怪,但请幽默一下......
最佳答案
在您的消息标签库中:
grailsApplication.getArtefactByLogicalPropertyName('Controller', pageScope.controllerName)
与 View 一样,您可以通过controllerName
和actionName
访问当前 Controller 和操作
关于taglib 中的 grails 访问 Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5462552/