sitemesh grails:如何处理模板中的脚本
我有一个布局 main.gsp,包括 /body 标记之前的脚本:
<g:pageProperty name="page.scripts" />
Index.gsp 是一个页面,其中 main.gsp 有一个模板,并使用
来包含一些 javascript,以便所有脚本在 /body 标记之前很好地保持在一起。
我将模板包含在我的页面 (index.gsp) 中,并带有以下说明:
<g:render template="postbox" />
为了使该模板可重用且独立,它需要自己的脚本。如何包含它并将其放置在 /body 标记之前?如果我使用
它会覆盖我在 index.gsp 中声明的脚本
I have a layout main.gsp including scripts before the /body tag:
<g:pageProperty name="page.scripts" />
Index.gsp is a page which has main.gsp has a template, and uses <content tag="scripts">
to include some javascript, so that all scripts stay nicely together before the /body tag
I have my template with I include in my page (index.gsp) with the following instruction:
<g:render template="postbox" />
for this template to reusable and independent, it needs its own script. How can I include it and have it placed right before the /body tag? If I use <content tag="scripts">
it overwrites the scripts I declared in index.gsp
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为您应该使用 Grails 资源插件。
该插件将组织您的 javascript 代码、javascript 依赖项,并且您可以模块化您的 javascript 文件,以便某些页面(或模板)依赖于特定的 javascript 文件。
您将能够创建一个 postbox.js 文件,并在 _postbox.gsp 模板中声明它依赖于 postbox.js 脚本。
该插件甚至会进一步决定是否最好将脚本放在 body 标记之前,或者放在 html 文件末尾的 /body 标记之前。它实现了 JS 和 CSS 操作的最佳实践。很棒的东西。
In my opinion you should use the Grails Resources Plugin.
This plugin will organize your javascript code, javascript dependencies, and you can modularize your javascript files so that some pages (or templates) depend on specific javascript files.
You will be able to create a postbox.js file , and declare in your _postbox.gsp template that it depends on postbox.js script.
The plugin will even go further and decide if it is best to put the script before the body tag, or at the end of your html file right before /body tag. It implements best practices for JS and CSS manipulation. Great stuff.