gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 22:22:41 24 4
gpt4 key购买 nike

尝试从 Grails 中的另一个 View 呈现一个 View 。

<g:render contextPath="??" template="first_view" />

我在 index.gsp 并愿意呈现在特定 Controller (例如:user/first_view.gsp)下找到的 View 。我知道正确的 View 路径应该设置在“contextPath”中,如文档中所述:http://grails.org/doc/latest/ref/Tags/render.html

应用 View 的上下文路径是什么?

最佳答案

我认为您根本不必设置上下文路径。来自渲染文档:

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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com