Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using partial template under view root [closed]

I have a partial template I'm including in my main.gsp.

This partial content will be slightly differnt for each controller/page on the site. Therefore I will have a seperate _headerDetails.gsp for each view directory.

This works fine except for the default application index.gsp. When I include a _headerDetails.gsp under root view directory I get the following error:

org.codehaus.groovy.grails.web.pages.exceptions.GroovyPagesException: Error processing GroovyPageView: Template not found for name [headerDetails] and path [//_headerDetails.gsp]

Does grails not allow partials in the root directory?

Main.gsp

<html>
    <head>
        <g:layoutTitle/>
        <r:layoutResources/>
        <link href="${resource(dir: 'css', file: 'style.css')}" type="text/css" rel="stylesheet">
    </head>

    <body class="home">

        <div id="wrapper">

            <div id="page_top"></div>

            <div id="content">
                <g:render template="/common/header" />

                <g:render template="headerDetails" />

                <br class="clear" />

                <g:layoutBody/>

                <br class="clear" />

            </div>

            <div id="page_bottom"></div>

            <g:render template="/common/footer" />  

        </div>

        <r:layoutResources/>

   </body>
</html>
like image 220
Thomas Buckley Avatar asked Mar 25 '12 18:03

Thomas Buckley


3 Answers

is it headDetails or headerDetails??

if its not a typo issue, try using a / before the template name to get to the root dir!

like image 130
gotomanners Avatar answered Nov 12 '22 20:11

gotomanners


<g:if test="${params.action.equals('')}">
  <g:render template="/headerDetails" />
</g:if>  
<g:else>
  <g:render template="headerDetails" />
</g:else>
like image 24
Thomas Buckley Avatar answered Nov 12 '22 22:11

Thomas Buckley


See chapter "Template basics > Shared templates" of the grails docs:

http://grails.org/doc/2.0.x/guide/theWebLayer.html#viewsAndTemplates

In this case you can place them in the root views directory at grails-app/views or any subdirectory below that location, and then with the template attribute use an absolute location starting with / instead of a relative location. For example if you had a template called grails-app/views/shared/_mySharedTemplate.gsp, you would reference it as:

<g:render template="/shared/mySharedTemplate" />
like image 1
Chris Avatar answered Nov 12 '22 20:11

Chris