[Zope-dev] A z3c.jbot without a monkey

Brian Sutherland brian at vanguardistas.net
Fri Jan 18 11:58:42 EST 2008


On Fri, Jan 18, 2008 at 04:35:58PM +0100, Malthe Borch wrote:
> Getting back to the monkey, perhaps it would make sense to formalize the
> way a template object gets its source file. The template class could
> adapt to an ``IFileSource`` implementation that would provide a filename.

What about zope.pagetemplate.interfaces.IPageTemplate?

Personally I like the way z3c.form.form.BaseForm approaches this:

    def render(self):
        '''See interfaces.IForm'''
        # render content template
        if self.template is None:
            template = zope.component.getMultiAdapter((self, self.request),
                IPageTemplate)
            return template(self)
        return self.template()

That way the template is just a multi adapter. I've made a zcml
directive that registers a template as just such a multi-adapter:

      <pagetemplate
        for=".view.SomeView .interfaces.IMyLayer"
        bindings="view request"
        template="templates/mytemplate.pt"
        />

"bindings" explicitly defines what names each of the adapted objects is
available as in the template. Because sometimes I don't only have a
context and request.

The only problem is that IPageTemplate is a bit heavy as an interface,
it would perhaps be nicer to have a parent interface that only defines a
__call__ method.

-- 
Brian Sutherland


More information about the Zope-Dev mailing list