[Zope3-Users] viewlets for specific interfaces

Luis De la Parra lparrab at gmx.net
Wed Sep 13 14:59:59 EDT 2006


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>






More information about the Zope3-users mailing list