【问题标题】:Sitemesh layout doesn't work with g.include tag in GrailsSitemesh 布局不适用于 Grails 中的 g.include 标记
【发布时间】:2011-11-13 02:42:21
【问题描述】:

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

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

在正文中有一个调用:

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

问题是站点网格布局从不应用。如果我删除包含调用一切正常。

我还没有在站点中找到有关此问题的参考。 有没有人找到解决此问题的方法或提示,将不胜感激!

谢谢

-巴勃罗·杜兰蒂

【问题讨论】:

    标签: layout grails gsp sitemesh


    【解决方案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>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-11-23
      • 1970-01-01
      • 2017-05-24
      • 2010-12-15
      • 2013-06-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多