2011-09-08 61 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>