Search code examples
grailsgroovygspmeta-tagssitemesh

How do I remove meta tag for layout?


I have defined a layout, 'mainTemplate' for my grails application. I use g:layoutHead (so my pages append their head section to the layouts).

But when I look into the source of my home page, I still get the meta info for the layout.

Though I get my page rendered in the defined template, but I suppose grails should have removed this meta info.

http://grails.org/doc/1.3.x/ref/Tags/layoutHead.html

How do I remove it? Or am I missing something here?


Solution

  • If you're using the <meta> tag to define the layout, it's not easily removable. However, you can use <g:applyLayout> in your views to avoid using the <meta> tag.

    <!-- a GSP view, e.g. views/foo/index.gsp -->
    <g:applyLayout name="main"><!-- value for "name" is the same as what you'd use in the meta tag -->
      <html>
        <head><title>My Decorated Page</title></head>
        <body>
          Some content
        </body>
      </html>
    </g:applyLayout>
    

    Essentially what you're doing is removing the <meta> tag from your view and then wrapping the contents of the view with the <g:applyLayout>.

    Admittedly, this is a lot of work; you'd need to update all of your views, and also probably update the scaffolded views in src/templates (if you're using scaffolding). To be honest, removing the <meta> tag from the final view seems largely unnecessary except for some very exceptional cases (e.g. a naming conflict with "layout", or that you just have to prevent those extra ~35 characters from being sent over the wire, which seems pretty micro-optimization-happy to me).