Grails

Output of tags is not processed by sitemesh when evaluating page meta data

Details

  • Type: Bug Bug
  • Status: Open Open
  • Priority: Major Major
  • Resolution: Unresolved
  • Affects Version/s: 1.2 final
  • Fix Version/s: None
  • Component/s: None
  • Labels:
    None
  • Testcase included:
    yes

Description

Today I tried to write a tag that would write out a dynamic meta tag so that the layout of a page can be determined at runtime, eg:

def useAdminLayout = { attrs ->
        def layoutSetting = ConfigurationHolder.config.weceem.admin.layout
        def layoutName = layoutSetting instanceof String ? layoutSetting : 'weceemadmin'
        out << "<meta name=\"layout\" content=\"$layoutName\"/>"
    }

Using this in a GSP page in <head> instead of inlining a <meta> tag, results in the layout not being picked up.

On further investigation it seems that any tag that renders <meta> tags is ignored by sitemesh.

Attached is a sample app that uses g:render to try to render the meta tag. It does not pick up any layout for the page (index.gsp_

Issue Links

Activity

Hide
Luke Daley added a comment -

This may be a workaround...

def page = request[com.opensymphony.module.sitemesh.RequestConstants.PAGE]
page.addProperty('meta.layout', 'whatever')

I don't know if this is set too late for SiteMesh to pick it up though.

Show
Luke Daley added a comment - This may be a workaround...
def page = request[com.opensymphony.module.sitemesh.RequestConstants.PAGE]
page.addProperty('meta.layout', 'whatever')
I don't know if this is set too late for SiteMesh to pick it up though.
Hide
Luke Daley added a comment -

FWIW, I have used a slightly different technique.

I created a <layout:body /> tag that rendered a different template depending on the context. That works.

Show
Luke Daley added a comment - FWIW, I have used a slightly different technique. I created a <layout:body /> tag that rendered a different template depending on the context. That works.
Hide
Lari Hotari added a comment -

This is because of the Grails/GSP specific Sitemesh integration introduced in Grails 1.2 GSP performance optimizations.

I think it would be possible to choose the layout by calling:

def page=request[org.codehaus.groovy.grails.web.sitemesh.GrailsPageFilter.GSP_SITEMESH_PAGE]
page.addProperty('meta.layout', 'whatever')

This works when "grails.views.gsp.sitemesh.preprocess = true".

I've written some explanations in this thread: http://markmail.org/thread/cn4n7t2ypxrrg5mq .

Show
Lari Hotari added a comment - This is because of the Grails/GSP specific Sitemesh integration introduced in Grails 1.2 GSP performance optimizations. I think it would be possible to choose the layout by calling:
def page=request[org.codehaus.groovy.grails.web.sitemesh.GrailsPageFilter.GSP_SITEMESH_PAGE]
page.addProperty('meta.layout', 'whatever')
This works when "grails.views.gsp.sitemesh.preprocess = true". I've written some explanations in this thread: http://markmail.org/thread/cn4n7t2ypxrrg5mq .
Hide
Lari Hotari added a comment -

I think there should be a grails taglib available for handling this use case.

Show
Lari Hotari added a comment - I think there should be a grails taglib available for handling this use case.
Hide
Marc Palmer added a comment -

I agree Lari - this is pretty ugly.

Perhaps we should move away from using meta tags for layout / sitemesh properties completely and add tags for it:

<g:setLayout name="whatever"/>
<g:setLayoutProperty name="x" value="y"/>

This then works in all situations.

Show
Marc Palmer added a comment - I agree Lari - this is pretty ugly. Perhaps we should move away from using meta tags for layout / sitemesh properties completely and add tags for it: <g:setLayout name="whatever"/> <g:setLayoutProperty name="x" value="y"/> This then works in all situations.

People

Vote (0)
Watch (0)

Dates

  • Created:
    Updated:
    Last Reviewed: