2011-09-08 66 views
2

我正在渲染一個包含g.include調用和sitemesh佈局的視圖。 的看法是這樣的: myview.gspSitemesh佈局不適用於Grails中的g.include標記

<html> 
    <head> 
     <meta name="layout" content="checkout" /> 
    </head> 
    <body>... 

身體內有一個調用到:

g.include(controller:"mycontroller", action:"myaction") 

問題是SiteMesh的佈局從未應用。如果我刪除包含調用事情工作得很好。

我還沒有在網站上發現這個問題的提及。 有沒有人找到解決這個問題或提示,將不勝感激!

感謝

-Pablo杜蘭蒂

回答

1

我的索引文件是這樣標的:

<html> 
<head> 
    <title>App Store For Publish, Download Android Apps</title> 
    <meta name="layout" content="main" /> 
    <parameter name="sideBarSetting" value="main"/> 
</head> 
<body> 
    <g:if test="${flash.message}"> 
     <div class="message">${flash.message}</div> 
    </g:if> 
    <g:announcements/> 
    <g:include controller="cache" action="showFeatured"/> 
    <g:include controller="cache" action="latestProducts"/> 
    <div class="push"></div> 
    <g:include controller="cache" action="mostPopular"/> 
    <div class="push"></div>   
    <g:include controller="cache" action="allCategories"/> 
</body> 

它工作在Grails的1.0,1.2.2和1.3.7現在。

在您試圖包含的每個操作中,都無法渲染視圖,而是渲染模板。模板文件只能有HTML片段,它可以不包括頭,元佈局等

在我的緩存控制器

def latestProducts = { 
    cache shared:true, validFor: 300 
    def htmlCacheManager = HtmlCacheManager.getInstance() 
    def key = 'latestProducts' 
    def content = htmlCacheManager.getHtmlContent(key) 
    if (!content) { 
     def products = productService.get5LatestProducts(params) 
     if (products){ 
      content = g.render(template:'/common/product/productLatestListTemplate', model:['productInstanceList' : products, 'type':'latest']) 
      htmlCacheManager.store(key, content, Boolean.TRUE) 
     } else { 
      log.debug('No latest product found') 
     } 
    } 
    render content ?: '' 
} 

模板文件:

<div class="list"> 
<fieldset> 
<legend><g:message code="product.latest"/> <g:link action="feed" controller="product" params="['type':type]" target="_blank"><img src="${resource(dir:'images', file:'feed-icon.gif')}" height='16' width='16' alt="Feeds"/></g:link></legend> 
    <g:each in="${productInstanceList}" var="product"> 
    <div class="product"> 
     <g:render template="/common/product/productSingleListTemplate" model="['product':product]" /> 
    </div> 
    </g:each> 
</fieldset> 
</div>