You are here: Home Blog Viewlets in Grok

Viewlets in Grok

by terlegard Jan 31, 2008 12:42 PM

I had a great time at the snow sprint. I paired with Martijn Faasen and Robert Marianski and we implemented viewlets for Grok. It's nearly finished. It is working, but it needs a few more tests before it will be merged to trunk.

This is what your viewlet code could look like:

class PortalHeader(grok.ViewletManager):
    grok.name('header')

class Logo(grok.Viewlet):
    grok.viewletmanager(PortalHeader)
    grok.template('logo')

    def update(self):
        self.willBeAvailableInTemplate = 8

A template that wants to render the 'header' viewlet would include this:

<div tal:content="structure provider:header" />

I wrote a sample grok application, grokremoteinclude , to make sure the grok viewlets were compatible with other zope3 packages dealing with viewlets. It's a buildout, running it will install the grok app, nginx and varnish. Read the README.txt for instructions how to get going. The application uses SSI which allows viewlets to be either cached or retrieved from another server. The same technique can be used in Plone which was recently reported by Sasha Vincic.

Viewlets in Grok are really nice - no zcml and no macros. The viewlets are in a seperate branch if you want to try them out.
Filed under: , , , , ,
comments powered by Disqus