Desidero che un viewlet si applichi alla vista di diversi tipi di contenuto nello stesso uovo python. Quello che ho fatto è di applicare l'interfaccia marcatore via browser/configure.zcmlUn modo migliore per etichettare i tipi di contenuto con un'interfaccia comune
<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>
E nel mio modello Grok-based che ho:
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)
Questo funziona. Ma sono interessato a sapere se c'è un modo migliore per farlo.