尝试从 Grails 中的另一个 View 渲染一个 View 。
<g:render contextPath="??" template="first_view" />
我位于index.gsp并愿意渲染在特定 Controller 下找到的 View (例如:user/first_view.gsp)。我知道 View 的正确路径应该在“contextPath”中设置,如文档中所述:http://grails.org/doc/latest/ref/Tags/render.html
应用程序 View 的 contextPath 是什么?
最佳答案
我认为您根本不必设置上下文路径。来自渲染文档:
Note that if the value of the template attribute starts with a '/' it will be resolved relative to the views directory. This is useful for sharing templates between views. Without the leading '/' it will be first be resolved relative to the current controller's view directory then, failing that, the top level views directory.
在您的情况( <g:render contextPath="??" template="first_view" />
)中,渲染标记将在当前 View 的目录中查找 _first_view.gsp。如果您希望它在用户 View 目录中找到模板,请将标记更改为 <g:render template="/user/first_view" />
注意模板属性中的路径必须以“/”开头
关于grails-2.0 - Grails 在另一个 View 中渲染 View 。 View 文件夹的上下文路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13455418/