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

그건 내가 실수를 저지른 오타입니다. 문제를 알아 냈어, 대답을 보라. 귀하의 답변을 절반 내 문제를 고맙습니다. –

+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" />