Html 在gsp模板中呈现内容
我是grails新手,我想将html表“cart_table”(当前在shoppingcart.gsp中)的内容写入到一个_cartemplate.gsp中,并通过包含此新模板在另一个gsp(如summary.gsp)中显示此表 目前我在shoppingcart.gsp中定义了如下表:Html 在gsp模板中呈现内容,html,grails,groovy,Html,Grails,Groovy,我是grails新手,我想将html表“cart_table”(当前在shoppingcart.gsp中)的内容写入到一个_cartemplate.gsp中,并通过包含此新模板在另一个gsp(如summary.gsp)中显示此表 目前我在shoppingcart.gsp中定义了如下表: <table id="newTable" style="display:none"> <thead><th>item name</th><th>
<table id="newTable" style="display:none">
<thead><th>item name</th><th>desc</th><th>business justification</th><th>start date</th><th>end date</th></thead>
<tbody></tbody>
</table>
如何将表格放入template.gsp?在确认页面中,如何显示表格?这将进一步详细说明如何呈现模板: 对于您的代码,听起来您只需在shoppingcart.gsp和summary.gsp中执行此操作:
<g:render template="carttemplate" />
那么_cartemplate.gsp将如下所示:
<table id="newTable" style="display:none">
<thead><th>item name</th><th>desc</th><th>business justification</th><th>start date</th> <th>end date</th></thead>
<tbody></tbody>
</table>
项目名称描述业务理由开始日期结束日期
唯一有点棘手的部分是如何通过javascript填充数据。如果需要多个地方,它可以重用相同的javascript,而不是将脚本放在.js文件中,并从呈现模板的任何gsp引用它。如果它们是不同的,那么你就不会得到大量的重用
还要注意,您可能需要在g:render标记中指定模板的目录。让我们假设这个结构:
- 观点
- 推车
- shoppingcart.gsp
- _carttemplate.gsp
- 总结
- 普惠制概述
- 推车
<g:render template="carttemplate" />
但summary.gsp需要做到:
<g:render template="/cart/carttemplate" />
<g:render template="/cart/carttemplate" />