2

I am rendering a view that combines a g.include invocation and a sitemesh layout. The view would be something like this: myview.gsp

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

within the body there is an invocation to:

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

The problem is the sitemesh layout is never applied. If I remove the include invocation things work just fine.

I haven't found references to this problem in the site yet. Has anyone found a workaround to this issue or a tip, will be much appreciated!

Thanks

-Pablo Duranti

Pablo Duranti
  • 19
  • 1
  • 3

1 Answers1

1

My index file is like underlying:

<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>

It works in Grails 1.0, 1.2.2 and now 1.3.7.

In each of actions you try to include, you can not render the view, but render the template instead. The template file can ONLY has fragments of HTML, it can NOT include the head, meta for layout, etc.

In my cache controller

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 ?: ''
}

The template file:

    <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>