我对Grails还是陌生的,因此很难找到有关此信息。我来自CakePHP,您可以在其中轻松创建一个以应用程序为主题的插件,而我正在尝试在Grails中复制这种设置。
我想创建可重复使用的布局和脚手架模板,以便使用Grails创建的所有应用程序都具有相同的外观。我已经在一个Grails应用程序中成功地自定义了布局和脚手架模板,并且正在探索将其包装到一个可以在另一个项目中导入的插件中,但是我还没有设法完成这项工作(我确实将该插件打包并导入到另一个项目中,但是我似乎无法弄清楚如何从应用程序访问插件的布局和脚手架模板。
实现此目标的最佳方法是什么?将其打包为插件甚至是个好主意,还是我应该简单地覆盖Grails的默认主布局并在每个项目中导入自己的脚手架模板?
如果去插件路线是一个好方法:
应用程序
可从主应用程序访问(仅在dev中)。该页面将
让我确认布局是否正常,并且可以
还提供其他使用此插件说明的开发人员
如何使用插件的模板。如何访问网页
从插件通过我的Grails应用程序?
如果插件不可行,您有什么建议?
最佳答案
是的,插件是一个不错的选择。我只引用documentation:
When a plugin provides a controller it may also provide default views to be rendered. This is an excellent way to modularize your application through plugins. Grails' view resolution mechanism will first look for the view in the application it is installed into and if that fails will attempt to look for the view within the plugin. This means that you can override views provided by a plugin by creating corresponding GSPs in the application's grails-app/views directory.
For example, consider a controller called BookController that's provided by an 'amazon' plugin. If the action being executed is list, Grails will first look for a view called grails-app/views/book/list.gsp then if that fails it will look for the same view relative to the plugin.
基本上,您可以通过访问插件的 View 来访问它们,就像 View 在应用程序本身中一样。
关于templates - 如何在Grails 3.x中创建可重用的布局和脚手架模板,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34679085/