templates - 为不同的内容类型重复使用相同的模板

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

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

最佳答案

为此创建一个接口(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/

相关文章:

plone - 使用 plone.app.discussion 也可以在FolderishType中启用评论

python-2.7 - 在 ZPublisher.HTTPRequest.FileUpload 上使用 is_zipfile

Plone 4.3 - 如何在没有 Grok 的情况下使用 Zc3.form 构建 Form 包?

c++ - 使用 `using` 或其他方式显式实例化函数模板

tinymce - 新的 PloneFormGen 表单文件夹具有用于序言和结语的纯文本格式

c++ - 模板 <typename T> 和模板 <class T> 有什么区别。对我来说,两者都产生相同的结果

parsing - Logstash 日期解析错误

portlet - 是否可以在 Plone 4.1 中使用 Five.grok 来注册 portlet?

c++ - 来自 boost::multi_array 的二维数组 - 无法编译

c++ - 将基于自定义模板的迭代器类的对象转换为 const_iterator