templates - 如何在Grails 3.x中创建可重用的布局和脚手架模板

标签 templates grails grails-plugin grails-3.0

我对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/

    相关文章:

    javascript - 将参数从<g:each>内部传递到javascript函数中的createLink中指定的操作,该操作在单击<a:>链接时被调用

    spring - 在 grails 中的 Controller 操作之间传递对象的最佳方式

    java - 如何分解一个庞大的 Grails 应用程序?

    templates - 比较 Mongoose 对象 ID 时,if 语句在 Jade 中不起作用

    c++ - `apply` 模板在 g++ 中编译但在 clang++ 和 vc++ 中不编译

    java - AssertEquals 与带有非原始模板参数的集合

    c++ - 模板类的赋值运算符

    events - 找不到Grails Spring Events插件

    grails - Grails Spring安全核心预注销

    grails - 关于Grails渲染的怀疑