2

我正在渲染一个结合了 g.include 调用和 sitemesh 布局的视图。视图将是这样的:myview.gsp

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

在体内有一个调用:

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

问题是永远不会应用站点网格布局。如果我删除包含调用,一切都会正常工作。

我还没有在网站上找到对这个问题的引用。有没有人找到解决此问题的方法或提示,将不胜感激!

谢谢

——巴勃罗·杜兰蒂

4

1 回答 1

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>
于 2011-09-08T17:40:55.420 回答