Plone 金属:使用宏和金属:在五个ViewPageTemplateFile中定义宏
我希望在单个五视图页面模板文件页面模板中使用宏,以避免复制粘贴代码 以下是我的尝试:Plone 金属:使用宏和金属:在五个ViewPageTemplateFile中定义宏,plone,Plone,我希望在单个五视图页面模板文件页面模板中使用宏,以避免复制粘贴代码 以下是我的尝试: <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/i1
<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>
然而,这里没有定义(据我所知,这是一种古老的独立页面模板方式)
如何从ViewPageTemplate.pt template中引用模板本身并在.pt文件中使用/定义宏?我想您需要:
<metal:macro use-macro="template/macros/row" />
使用
ViewPageTemplateFile
时,您可以(至少)访问模板中的以下变量:
- 这里
- 模板
- 看法
template/macros
来访问您的“row”宏,而不是“here”(这相当于view/context
),因为@davisagli表示它也可能
<metal:macro use-macro="here/ViewPageTemplate/macros/row" />
使用“context”而不是“here”是否有帮助?我正在使用带有自定义GrokView的Plone 4.2.2,这个代码段给了我一个LocationError。模板摘录:|回溯: