[Zope3-Users] viewlets for specific interfaces

Darryl Cousins darryl at darrylcousins.net.nz
Thu Sep 14 00:23:46 EDT 2006


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