2012-03-25 4 views
5

私はmain.gspに含まれている部分テンプレートがあります。ビュールートの下に部分テンプレートを使用

この部分的な内容は、サイトのコントローラ/ページごとに若干異なります。 したがって、私はビューディレクトリごとに別々の_headerDetails.gspを持っています。

これは、デフォルトのアプリケーションindex.gspを除いて正常に動作します。 私はルートビューディレクトリの下_headerDetails.gspが含まれている場合、私は次のエラーを取得する:

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

Grailsはルートディレクトリにパーシャルを許可しませんか?

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> 
+0

この質問とその答えは、私を助けました。それがどのように "ローカライズされている"かを確認できません。とにかく過度の緩和に感謝します。 –

答えて

5

それはheadDetails又はheaderDetailsあります?

もしそれがタイプミスでなければ、テンプレート名の前に/を使ってルートディレクトリに行ってみてください!

+1

これは、私がgotomannersを固定したタイプミスです。問題を解明し、答えを参照してください。あなたの答えの半分が私の問題を修正しました。 –

+0

スラッシュの接頭辞は私にとってうまくいきました、ありがとう – peterp

3
<g:if test="${params.action.equals('')}"> 
    <g:render template="/headerDetails" /> 
</g:if> 
<g:else> 
    <g:render template="headerDetails" /> 
</g:else> 
1
Grailsのドキュメントの

を参照してください章 "テンプレートの基礎>共有テンプレート":

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" /> 
関連する問題