2012-03-25 17 views
5

Tôi có một phần mẫu mà tôi bao gồm trong số main.gsp của mình.Sử dụng mẫu từng phần dưới gốc chế độ xem

Nội dung một phần này sẽ hơi khác biệt đối với mỗi bộ điều khiển/trang trên trang web. Vì vậy, tôi sẽ có một riêng biệt _headerDetails.gsp cho mỗi thư mục xem.

Tính năng này hoạt động tốt ngoại trừ ứng dụng mặc định index.gsp. Khi tôi bao gồm _headerDetails.gsp dưới xem gốc thư tôi nhận được lỗi sau:

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

Liệu grails không cho phép partials trong thư mục gốc?

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

Câu hỏi này, và câu trả lời của mình, đã giúp tôi. Không thấy nó "Quá địa phương hóa". Cảm ơn anyway cho quá mức kiểm duyệt. –

Trả lời

5

là nó headDetails hoặc headerDetails ??

nếu không phải là lỗi chính tả, hãy thử sử dụng / trước tên mẫu để truy cập thư mục gốc!

+1

Đó là một lỗi đánh máy tôi đã cố định gotomanners. Đã tìm ra vấn đề, xem câu trả lời. Câu trả lời của bạn một nửa khắc phục sự cố của tôi, cảm ơn. –

+0

Tiền tố với dấu gạch chéo làm việc tốt cho tôi, cảm ơn – peterp

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

Xem chương "Mẫu cơ bản> Shared mẫu" của các tài liệu 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" /> 
Các vấn đề liên quan