我可以在 GSP 之外使用 grails 标签吗? [英] Can I use grails tag outside of GSP?
本文介绍了我可以在 GSP 之外使用 grails 标签吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
例如,我可以把
<g:createLink controller="user" action="show" />
在 .gsp 文件中,它会很好地工作.
inside a .gsp file and it will work nicely.
但我也想在不属于 grails 视图的 .groovy 文件中使用相同的闭包 createLink
But also I'd like to use the same closure createLink
inside a .groovy file which is not part of the grails views
推荐答案
您可以使用 Grails 控制器中的 taglib 方法,例如:
You can use taglib methods from Grails controllers, for example:
def userShow = g.createLink(controller:"user", action:"show")
对于内置标签库(或 g 命名空间中的那些),您可以在方法调用中省略命名空间前缀.
For builtin taglibs (or those in the g namespace) you can omit the namespace prefix in the method call.
这篇关于我可以在 GSP 之外使用 grails 标签吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文