Using a partial template under the root of the view

I have a partial template that I include in my own main.gsp.

This partial content will be slightly different for each controller / page on the site. Therefore, for each directory of representation I will have a separate one _headerDetails.gsp.

This works great except for the default application index.gsp. When I include the directory _headerDetails.gspunder the root view, 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 allow partial files to be allowed 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>
+5
source share
3 answers

is it headDetailsor headerDetails?

, / , dir!

+5
<g:if test="${params.action.equals('')}">
  <g:render template="/headerDetails" />
</g:if>  
<g:else>
  <g:render template="headerDetails" />
</g:else>
+3

See the "Template Basics> General Templates" chapter of grails docs:

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

In this case, you can put them in the root representations directory in grails-app/viewsor any subdirectory below this location, and then use the absolute location with the template attribute, starting with /instead of the relative location. For example, if you have a template called grails-app/views/shared/_mySharedTemplate.gsp, you would link to it as:

<g:render template="/shared/mySharedTemplate" />
+1
source

All Articles