我想知道是否可以使用g:include來僅包含給定頁面的正文內容。Grails 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)只包括book/list頁面中定義的表格。但是,當我嘗試這個包括整個html定義(<html>
標籤和所有)。
是否有可能以某種方式做到這一點?我嘗試過像<g:include controller="book" action="list" view="someView.gsp"/>
之類的東西,但這不起作用。我真的想要避免必須向「索引控制器」添加書目列表邏輯,我想重新使用現有的控制器。
我不能成爲第一個有這種用例的人,你們提出了什麼解決方案?
這正是我正在尋找的,謝謝一大堆! – netbrain 2011-06-14 18:35:55
這是否仍然是正確的方法。 – Nix 2013-02-26 14:37:24