我有一个用于渲染的模板:
<g:render template="recordInfo" />
在我的主要布局中。(布局/main.gsp)。
那是一个模板,我的一些视图需要它,而一些视图不需要。
对于不需要该模板的视图,我在顶层视图目录 (/grails-app/views) 中放置了一个名称为空的文件。如 grails 文档中所述:
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.
它适用于在自己的视图目录中具有模板文件的视图(例如/grails-app/views/address)。但它不起作用,grails 应该在 /grails-app/views 级别搜索模板。
我是否从文档中理解了错误,或者我的代码中有错误?
我的文件/目录结构如下所示:
...
MyApp/grails-app/views/_recordInfo.gsp
MyApp/grails-app/views/address/_form.gsp
MyApp/grails-app/views/address/ ...
MyApp/grails-app/views/address/_recordInfo.gsp
MyApp/grails-app/views/contact/_form.gsp
MyApp/grails-app/views/contact/ ...
...
地址视图需要一个自定义的 _recordInfo 模板,而联系人视图不需要它(因此我认为 grails 会选择 MyApp/grails-app/views 目录中的那个...)