[Zope3-Users] Re: viewlets for specific interfaces
Luis De la Parra
lparrab at gmx.net
Thu Sep 14 13:15:42 EDT 2006
hello,
yes. I guess that would do the trick, but I'd be moving configuration into
the code, which I think belongs in the zcml... (which sometimes can be a
good thing, but I think this particular configuration fits better in the
zcml)
what is the pourpose of the "for" option in the zcml directive anyways??
It'd be nice if I could define my interfaces (plural!) for which the viewlet
should render without changing the code.
thanks anyways.
cheers. luis
Darryl Cousins wrote:
> Hi,
>
> Try testing the context interface in update.
>
> dorender = False
> def update(self):
> if MyInterface.providedBy(self.context):
> self.dorender = True
>
> def render(self):
> if self.dorender:
> return u'Hello'
> else:
> return u''
>
> That may do it.
>
> Regards,
> Darryl
>
> On Wed, 2006-09-13 at 20:59 +0200, Luis De la Parra wrote:
>> hello,
>>
>> I'm trying to get started with viewlets, but am still having some
>> problems:
>>
>> For example, I have a "LeftColumn" viewletmanager, where I want to
>> display different infos (viewlets) depending on the object that's being
>> displayed (one viewlet for folders, one for "normal" files, one for
>> images, etc)
>>
>> the following example works either for all interfaces or for none, and
>> I'm trying to figure out how to render a particular viewlet only for a
>> particular interface...
>>
>> any pointers in the right direction? thanx a lot! Luis
>>
>>
>> #### test/__init__.py
>> ############################################################
>> from zope import component
>> from zope import interface
>> from zope import viewlet
>>
>> class ILeftColumn(viewlet.interfaces.IViewletManager):
>> """ Viewlet manager for the left column"""
>>
>>
>> class HelloMessage(object):
>> interface.implements(viewlet.interfaces.IViewlet)
>>
>> def __init__(self,context,request,view,manager):
>> self.__parent__ = view
>> self.context, self.request = context,request
>>
>> def update(self):
>> pass
>>
>> def render(self):
>> return u'<div>Hello!</div>'
>>
>> #### test/configure.zcml
>> ############################################################
>> <configure
>> xmlns="http://namespaces.zope.org/zope"
>> xmlns:browser="http://namespaces.zope.org/browser">
>>
>> <browser:page
>> for="*"
>> name="viewlet.html"
>> template="index.pt"
>> permission="zope.View"/>
>>
>> <browser:viewletManager
>> name="vm"
>> permission="zope.Public"
>> provides=".ILeftColumn"
>> template="vm.pt"/>
>>
>> <!-- ###########################
>>
>> for="*" shows "hello" for any object
>> for="zope.app.file.interfaces.IFile"
>> does not work for any object, IFiles
>> included. why ???
>> ##########################
>> -->
>> <browser:viewlet
>> name="hello"
>> for="zope.app.file.interfaces.IFile"
>> manager=".ILeftColumn"
>> class=".HelloMessage"
>> permission="zope.Public"/>
>>
>> </configure>
>>
>>
>>
>>
>> _______________________________________________
>> Zope3-users mailing list
>> Zope3-users at zope.org
>> http://mail.zope.org/mailman/listinfo/zope3-users
More information about the Zope3-users
mailing list