同じpythonegg内の複数のコンテンツタイプのビューにビューレットを適用したいと思います。私がやっていることは、browser/configure.zcmlを介してマーカーインターフェイスを適用することです
<configure
xmlns="http://namespaces.zope.org/zope"
xmlns:browser="http://namespaces.zope.org/browser"
i18n_domain="AnnualProgramModule.content">
<include package="plone.app.contentmenu" />
<class class="..content.programyear.ProgramYear">
<implements interface=".viewlets.IAnnualProgram" />
</class>
<class class="..content.institution.Institution">
<implements interface=".viewlets.IAnnualProgram" />
</class>
</configure>
そして、Grokベースのテンプレートには次のものがあります。
from zope.interface import Interface
from five import grok
from plone.app.layout.viewlets.interfaces import IAboveContentTitle
from AnnualProgramModule.content.interfaces import IInstitution
grok.templatedir('templates')
class IAnnualProgram(Interface):
"""Marker Interface for AnnualProgram content types
"""
class AnnualProgramViewlet(grok.Viewlet):
grok.require('zope2.View')
grok.viewletmanager(IAboveContentTitle)
grok.context(IAnnualProgram)
class InstitutionViewlet(grok.Viewlet):
grok.require('zope2.View')
grok.context(IInstitution)
grok.viewletmanager(IAboveContentTitle)
これは機能します。しかし、私はそれを行うためのより良い方法があるかどうかを知りたいと思っています。