Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/templates/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Templates 对不同的内容类型重复使用相同的模板_Templates_Plone_Grok_Dexterity - Fatal编程技术网

Templates 对不同的内容类型重复使用相同的模板

Templates 对不同的内容类型重复使用相同的模板,templates,plone,grok,dexterity,Templates,Plone,Grok,Dexterity,我正在创建相当多的灵巧内容类型(感谢devs!!),但即使我需要它们是不同的内容类型(搜索、集合…),它们中的一些将被同等地呈现 那么,有没有办法为不同的内容类型重用相同的模板 好的,我成功了,但我想知道这是否是正确的方法: from my.product.parent_type import IParentType, ParentType, TwoColumnsView ... code omitted ... # Common folder for templates grok.temp

我正在创建相当多的灵巧内容类型(感谢devs!!),但即使我需要它们是不同的内容类型(搜索、集合…),它们中的一些将被同等地呈现

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

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

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

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

为此创建一个界面:

from zope.interface import Interface

class ITwoColumnViewable(Interface):
    """Can be viewed in a 2-column layout"""
然后将此接口分配给各种内容类型,并注册该接口的视图,而不是直接注册类型:

class SameTwoColumnsView(TwoColumnsView):
    grok.context(ITwoColumnViewable)