2012-10-31 35 views
6

Tôi muốn sử dụng macro trong một mẫu Five ViewPageTemplateFile duy nhất để tránh sao chép mã của tôi xung quanh.kim loại: sử dụng macro và kim loại: define-macro trong Five ViewPageTemplateFile

Dưới đây là nỗ lực của tôi:

<html xmlns="http://www.w3.org/1999/xhtml" 
     xmlns:tal="http://xml.zope.org/namespaces/tal" 
     xmlns:metal="http://xml.zope.org/namespaces/metal" 
     xmlns:i18n="http://xml.zope.org/namespaces/i18n" 
     tal:omit-tag="" 
     > 

    <metal:row define-macro="row"> 
     <tal:block repeat="widget view/widgets"> 
      <div tal:attributes="class python:'%s%s' % (widget.klass, widget.mode=='hidden' and ' hidden' or '')" 
       tal:condition="python:view._includeRow(widget.name)"> 

       <div tal:replace="structure widget/render"></div> 

      </div> 
     </tal:block> 
    </metal:row> 

    <table class="datagridwidget-table-view" tal:attributes="data-extra view/extra"> 
     <thead> 
      <tr> 
       <th class="header"> 
        <!-- --> 
       </th> 
       <th id="" class="header" tal:condition="view/allow_insert"></th> 
       <th id="" class="header" tal:condition="view/allow_delete"></th> 
       <th id="" class="header" tal:condition="view/allow_reorder"></th> 
       <th id="" class="header" tal:condition="view/allow_reorder"></th> 
      </tr> 
     </thead> 
     <tbody class="datagridwidget-body" tal:attributes="data-name_prefix view/name_prefix; data-id_prefix view/id_prefix"> 
      <tal:row repeat="widget view/getNormalRows"> 
       <tr> 
        <metal:macro use-macro="here/row" /> 
       </tr> 
      </tal:row> 

      <tal:row condition="view/getTTRow" define="widget view/getTTRow"> 
       <tr> 
        <metal:macro use-macro="here/row" /> 
       </tr> 
      </tal:row> 


      <tal:row condition="view/getAARow" define="widget view/getAARow"> 
       <tr> 
        <metal:macro use-macro="here/row" /> 
       </tr> 
      </tal:row> 


    </tbody> 
</table> 
<input type="hidden" tal:replace="structure view/counterMarker" /> 
</html> 

Tuy nhiên, đây không được định nghĩa (vì nó là cũ độc lập trang mẫu cách làm việc như xa như tôi biết).

Làm cách nào tôi có thể tự giới thiệu mẫu từ mẫu ViewPageTemplate .pt và sử dụng/xác định macro trong tệp .pt?

+0

Có sử dụng 'bối cảnh' thay vì 'ở đây', giúp đỡ? –

Trả lời

7

Tôi nghĩ rằng bạn muốn:

<metal:macro use-macro="template/macros/row" /> 
+0

Tôi đang sử dụng Plone 4.2.2 với một GrokView tùy chỉnh và đoạn mã này cho tôi một LocationError. Đoạn trích mẫu: http://pastebin.com/VgDjKYTV | Traceback: http://pastebin.com/7PeK94WE –

3

Khi bạn sử dụng ViewPageTemplateFile bạn có quyền truy cập vào (ít nhất) các biến sau trong mẫu của bạn:

  • đây
  • mẫu
  • xem

Vì vậy, thay vì "đây" (tương đương với view/context), bạn có thể sử dụng để truy cập template/macros "hàng" của bạn vĩ mô như @davisagli chỉ

1

Nó cũng có thể thích

<metal:macro use-macro="here/ViewPageTemplate/macros/row" /> 
Các vấn đề liên quan