是什么导致 gsp 的 html 头中的脚本块被覆盖
What is is causing the script block in the html head of a gsp to be overwritten
我有 2 个 grails 视图,它们都引用相同的布局:
index.gsp & custom.gsp
两个页面在 <head>
中都有一个 <script>
块。我希望能够直接转到 custom.gsp 或使用 index.gsp 中选项卡中的内容.
我使用以下方式包含 custom.gsp 内容:
<g:include controller='controllername' action='custom'/>
似乎 custom.gsp 的 <script>
块正在覆盖 index.gsp 的 <script>
块。如果我删除 include
索引页面上的所有其他内容都正常运行。如果我添加 include
index.gsp 的 <script>
块中的代码不会执行,并且经检查似乎不存在。
这里到底发生了什么,为什么?我怎样才能以不同的方式构建事物,以免发生这种情况?
更新
我试过将 custom.gsp 中的代码从 <script>
块中移出并移到单独的 javascript 文件中。然而;当包含现在发生时,它仍然将代码作为 <script>
块拉入并替换旧的。
我试过将每个块移动到正文中,并且尝试为每个块添加 id 属性,我想也许 sitemesh 可能会将其视为一个独特的块。仍然没有运气。
更新 #2
我尝试将此添加到 index.gsp:
的正文中
<div>this is a script
<script type="application/javascript">
var xyz='xyz';
</script>
</div>
文字this is a script
可见,但脚本不见了!
更新#3
更新 #2 是错误的,文本是可见的,但脚本实际上也在那里。我 认为 它消失了,因为我观察到的行为与它消失时的行为相同。然而;真正的问题是 index.gsp 的整个头部被包含页面的头部替换,因此 index.gsp 丢失了执行脚本代码所需的库。
正如 @joshua 评论的那样 return 通过此调用编辑的视图:
<g:include controller='controllername' action='custom'/>
必须是一个片段而不是带有 html, head ..
个标签的整个 gsp 视图。
如果您有 HomeController
和 NewsController
(检查下图),并且您想要包含 NewsController's
视图,请在使用 g:include
包含视图时考虑这一点HomeController's
查看,
您必须在 NewsController
上定义一个操作,该操作只会 return 您在图中看到的 content fragment
。为此,您可以保留 news.gsp
视图,但以将内容部分放入新模板 (content fragment
) 的方式重构它。我希望你明白我的意思,但如果我的例子中有什么不清楚的地方,请发表评论。
我有 2 个 grails 视图,它们都引用相同的布局:
index.gsp & custom.gsp
两个页面在 <head>
中都有一个 <script>
块。我希望能够直接转到 custom.gsp 或使用 index.gsp 中选项卡中的内容.
我使用以下方式包含 custom.gsp 内容:
<g:include controller='controllername' action='custom'/>
似乎 custom.gsp 的 <script>
块正在覆盖 index.gsp 的 <script>
块。如果我删除 include
索引页面上的所有其他内容都正常运行。如果我添加 include
index.gsp 的 <script>
块中的代码不会执行,并且经检查似乎不存在。
这里到底发生了什么,为什么?我怎样才能以不同的方式构建事物,以免发生这种情况?
更新
我试过将 custom.gsp 中的代码从 <script>
块中移出并移到单独的 javascript 文件中。然而;当包含现在发生时,它仍然将代码作为 <script>
块拉入并替换旧的。
我试过将每个块移动到正文中,并且尝试为每个块添加 id 属性,我想也许 sitemesh 可能会将其视为一个独特的块。仍然没有运气。
更新 #2
我尝试将此添加到 index.gsp:
的正文中<div>this is a script
<script type="application/javascript">
var xyz='xyz';
</script>
</div>
文字this is a script
可见,但脚本不见了!
更新#3
更新 #2 是错误的,文本是可见的,但脚本实际上也在那里。我 认为 它消失了,因为我观察到的行为与它消失时的行为相同。然而;真正的问题是 index.gsp 的整个头部被包含页面的头部替换,因此 index.gsp 丢失了执行脚本代码所需的库。
正如 @joshua 评论的那样 return 通过此调用编辑的视图:
<g:include controller='controllername' action='custom'/>
必须是一个片段而不是带有 html, head ..
个标签的整个 gsp 视图。
如果您有 HomeController
和 NewsController
(检查下图),并且您想要包含 NewsController's
视图,请在使用 g:include
包含视图时考虑这一点HomeController's
查看,
您必须在 NewsController
上定义一个操作,该操作只会 return 您在图中看到的 content fragment
。为此,您可以保留 news.gsp
视图,但以将内容部分放入新模板 (content fragment
) 的方式重构它。我希望你明白我的意思,但如果我的例子中有什么不清楚的地方,请发表评论。