grails-2.0 - Grails 在另一个 View 中渲染 View 。 View 文件夹的上下文路径

标签 grails-2.0

尝试从 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/

相关文章:

grails - 在 Grails 中,如何获得鉴别器值?

java - com.amazonaws.services.s3.model.AmazonS3Exception : Forbidden (Service: Amazon S3; Status Code: 403; Error Code: 403 Forbidden; Request ID: XXXXXXXX)

grails - 使用 springSecurity 制作 grails 应用程序的索引 UI

Grails 2.3.6 脚手架索引页抛出 ArrayIndexOutOfBoundsException

Grails 'method not allowed' 怪异

authentication - 如何在 Grails 中使用 Spring Security 检查用户在线状态?

image - 带有Grails资源插件的图片网址

image - 在grails中将图像保存到Web应用程序下的文件夹

java - 未找到 Spring Security 的 Spring Bean 还记得我吗?

java - 从 Grails 启动命令行程序?