Skip to content

GRAILS-11993: Sitemesh layouts should not be applied for the include tag. #1168

Closed

Description

@graemerocher

Original Reporter: pgr
Environment: Not Specified
Version: 2.4.4
Migrated From: http://jira.grails.org/browse/GRAILS-11993

It results in invalid HTML as you cannot nest one HTML page in another.

To verify:

Create a new empty project with current version of Grails (2.4.4) and create a controller:

DemoController:

{code:title=DemoController.groovy}
class DemoController {

        def index() {
            println 'index called'
        }

        def partial() {
            println 'partial called'
            render(view: '_partial')
        }

    }

{code}

View (/demo/index.gsp):

{code:title=/demo/index.gsp}


    </head>
    <body>
    From index gsp
    <g:include action="partial" />
    </body>
    </html>

{code}

View (/demo/_partial.gsp):

{code:title=/demo/_partial.gsp}

From partial gsp


{code}

Since no Sitemesh template specified above (and no layout called application.gsp), you get this HTML as expected when you visit http://localhost:8080/<project-name>/demo/index:

{code}


</head>
<body>
From index gsp
<p>From partial gsp</p>
</body>
</html>

{code}

But then try to rename main.gsp to application.gsp and reload the page in the browser.
Now application.gsp has been applied twice resulting in invalid HTML and your header and footer are displayed twice. It should only be applied once.

It doesn't help to specify en empty template via the render method, nor the via the applyLayout tag:

DemoController:

{code:title=DemoController.groovy}
class DemoController {

        def index() {
            println 'index called'
        }

        def partial() {
            println 'partial called'
            render(view: '_partial')
        }

        def partialWithEmptyTemplate() {
            println 'partial with empty template called'
            render(template: 'empty', view: '_partial')
        }

    }

{code}

View (/demo/index.gsp):

{code:title=index.gsp}


    </head>
    <body>
    From index gsp
    <g:include action="partialWithEmptyTemplate" />
    </body>
    </html>

{code}

Empty Layout Template (/layouts/empty.gsp):

{code:title=/layouts/empty.gsp}
<g:layoutBody />
{code}

Or:

View (/demo/index.gsp):

{code:title=/demo/index.gsp}


    </head>
    <body>
    From index gsp
    <g:applyLayout name="empty">
    <g:include action="partial" />
    </g:applyLayout>
    </body>
    </html>

{code}

Try to do the same in Grails 2.2.4 which is the version I'm upgrading from. All 3 scenarios works.

Activity

  1. graemerocher commented on Feb 18, 2015

    @graemerocher
    ContributorAuthor

    pgr said:
    UPDATE: I think I'm wrong about the example where I include the action partialWithEmptyTemplate. I guess the template argument for the render method has nothing to do with a Sitemesh Layout Template. But the other two examples works in 2.2.4. Sorry for the mistake. :-)

  2. added this to the grails-2.5.1 milestone on May 27, 2015
  3. graemerocher commented on May 28, 2015

    @graemerocher
    ContributorAuthor

    This works fine with 2.5.x in master

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions