为不同的内容类型重用相同的模板

时间:2011-07-21 14:42:35

标签: templates plone grok dexterity

我正在创建相当多的Dexterity内容类型(感谢zopeskel.dexterity开发!!)但即使我需要它们是不同的内容类型(搜索,集合......),其中一些将被渲染同样。

那么,有没有办法为不同的内容类型重用相同的模板?

好的,我做到了,但我想知道这是否是正确的方法:

from my.product.parent_type import IParentType, ParentType, TwoColumnsView

... code omitted ...

# Common folder for templates
grok.templatedir('parent_type_templates')

class SameTwoColumnsView(TwoColumnsView):
    grok.context(CustomClass)
    grok.require('zope2.View')

    grok.template("twocolumnsview")

有什么想法? 如何跨内容类型重复使用模板?

1 个答案:

答案 0 :(得分:6)

为此创建一个界面:

from zope.interface import Interface

class ITwoColumnViewable(Interface):
    """Can be viewed in a 2-column layout"""

然后将此接口分配给各种内容类型,并直接为该接口注册视图:

class SameTwoColumnsView(TwoColumnsView):
    grok.context(ITwoColumnViewable)
相关问题