我正在创建相当多的 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")
有什么想法吗? 如何跨内容类型重复使用模板?
最佳答案
为此创建一个接口(interface):
from zope.interface import Interface
class ITwoColumnViewable(Interface):
"""Can be viewed in a 2-column layout"""
然后将此接口(interface)分配给各种内容类型,并为该接口(interface)注册 View ,而不是直接为类型注册 View :
class SameTwoColumnsView(TwoColumnsView):
grok.context(ITwoColumnViewable)
关于templates - 为不同的内容类型重复使用相同的模板,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6777900/