Grails:从标签库中获取当前视图名称
有什么方法可以找出正在评估的当前视图(或 gsp 文件)?
由于 URL 映射和转发,RequestURI 不起作用。
我正在尝试根据当前的 GSP 文件动态检索资源。例如,如果正在执行product/view.gsp,我想包含product/view.css和product/view.js(如果它们存在)。我遇到问题的部分是获取文本“view”
Is there any way to find out the current view (or gsp file) that is being evaluated?
RequestURI doesn't work due to URL Mappings and forwards.
I'm trying to retrieve resources dynamically based on the current GSP file. For example, if product/view.gsp is being executed, I want to include product/view.css and product/view.js (if they exist). The part that I'm having a problem with is getting the text "view"
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
gsp 页面被编译为派生自 org.codehaus.groovy.grails.web.pages.GroovyPage。您可以使用
${this.getGroovyPageFileName()}
或仅${groovyPageFileName}
获取 gsp 文件的完整路径名。您必须自己修剪路径信息。A gsp page is compiled into a class derived from org.codehaus.groovy.grails.web.pages.GroovyPage. You can get the whole pathname of the gsp file with
${this.getGroovyPageFileName()}
, or just${groovyPageFileName}
. You'll have to trim off the path information yourself.