我想知道是否可以使用 g:include 仅包含给定页面的正文内容。
假设我有一个主布局页面,如下所示:
<html>
<head>
<title>My start page</title>
<g:layoutHead>
</head>
<body>
<g:layoutBody>
</body>
</html>
然后是主页(index.gsp)
<html>
<head>
<!-- main layout reference -->
<meta name="layout" content="main"/>
</head>
<body>
THIS IS MY INDEX BODY CONTENT WITH AN INCLUDE
<g:include controller="book" action="list"/>
<g:link controller="book" action="list">See the full list!</g:link>
</body>
</html>
最后是书籍/列表页面
<html>
<head>
<!-- main layout reference -->
<meta name="layout" content="main"/>
</head>
<body>
<table>
<g:each in="${books}">
<tr>
<td>${it.author}</td>
<td>${it.title}</td>
<td>${it.price}</td>
</tr>
</g:each>
</table>
</body>
</html>
所以我想要实现的是主页(index.gsp)只包含在书/列表页面中定义的表格。但是,当我尝试这个时,它包括定义的整个 html(<html>
标签和所有)。
有可能以某种方式做到这一点吗?我已经尝试过类似的事情,<g:include controller="book" action="list" view="someView.gsp"/>
但这不起作用。我真的很想避免将书单逻辑添加到我想重用现有控制器的“索引控制器”中。
我不可能是第一个有这个用例的人,你们想出了什么解决方案?