2012-10-31 23 views
6

Chciałbym użyć makra w jednym szablonie strony Five ViewPageTemplateFile, aby uniknąć wklejania mojego kodu dookoła.metal: use-macro and metal: define-macro within Five ViewPageTemplateFile

Poniżej moja próba:

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

Jednak tutaj nie jest zdefiniowane (jak to jest stary sposób niezależny szablon strony robienia rzeczy o ile wiem).

Jak mogę odnieść szablon z szablonu ViewPageTemplate .pt i użyć/zdefiniować makra w pliku .pt?

+0

Czy używając „kontekst” zamiast "tutaj", pomóż? –

Odpowiedz

7

Myślę, że chcesz:

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

Używam Plone 4.2.2 z niestandardowym GrokView, a ten fragment daje mi błąd LocationError. Fragment szablonu: http://pastebin.com/VgDjKYTV | Traceback: http://pastebin.com/7PeK94WE –

3

Podczas korzystania ViewPageTemplateFile masz dostęp do (przynajmniej) następujące zmienne w szablonie:

  • tutaj
  • szablon
  • widoku

Więc zamiast „tu” (co jest równoważne view/context) można użyć template/macros dostęp do wiersza „makro” jako @davisagli wskazuje

1

Może także

<metal:macro use-macro="here/ViewPageTemplate/macros/row" /> 
Powiązane problemy