[Zope3-Users] pagelets vs. pages

Stephan Richter srichter at cosmos.phy.tufts.edu
Wed Jun 27 02:43:03 EDT 2007


On Tuesday 26 June 2007 12:46, Hermann Himmelbauer wrote:
> At first, thanks for your reply, this clears things up a lot for me. The
> link to the Blog-entry above was also very valuable.

Great!

> What I still don't understand is how to implement a simple, quasi-static
> html-page. With browser:page I'd do it like this:
>
>   <browser:page
>       name="index.html"
>       for="myapp.interfaces.IMyApp"
>       template="index.pt"
>       layer="swarmfinder.layer.IMyAppLayer"
>       permission="zope.Public"
>       />

I'll note that Zope 3 does a lot of black magic to make this directive work 
correctly.

> And the template "mypage1.pt" would e.g. use the "body" macro and have some
> static content.

Right.

> In case of pagelets, I'd do it like this (correct me if I'm wrong):
>
>   <z3c:pagelet
>       for="*"
>       name="index.html"
>       permission="zope.View"
>       class=".MyAppPage1"
>       layer="z3c.layer.pagelet.IPageletBrowserLayer"
>       />
>
>     <z3c:template
>       for=".MyAppPage1"
>       layer="z3c.layer.pagelet.IPageletBrowserLayer"
>       template="mypage1.pt"
>       />
>
> And then I'd have to implement an interface and a class:
>
> class IMyAppPage1(zope.interface.Interface):
>   pass
>
> class MyAppPage1(BrowserPagelet)
>   implements(IMyAppPage1)
>
> This is a lot more code than with the browser:page example.
> As a solution, I'm thinking about a magic "template" directive in the
> z3c:pagelet namespace, e.g. something like that:
>
>   <z3c:pagelet
>       for="*"
>       name="index.html"
>       permission="zope.View"
>       template="mypage1.pt"
>       layer="z3c.layer.pagelet.IPageletBrowserLayer"
>       />

This example is longer than it needs to be. For starters, you do not need the 
interface; in your example it serves no use. Optionally, if you do not need 
to keep template registration independent of view registration, the following 
will work as well:

class MyAppPage1(BrowserPagelet):
    template = viewpagetemplatefile.ViewPageTemplateFile('mypage1.pt')

<z3c:pagelet
    for="*"
    name="index.html"
    permission="zope.View"
    class=".MyAppPage1"
    layer="z3c.layer.pagelet.IPageletBrowserLayer"
    />

In our experience, we rarely do static pages, maybe one every 20-30 other 
views. Then, we purposefully did not provide the semantics of the 
browser:page directive, because we *want* transparency. So why optimize this 
rare use case at the cost of losing transparency?

> Perhaps in case of this "template" directive, the interface/view class
> could be created on the fly? What do you think?

No, one of the (maybe implicit) goals of pagelets is to require view classes 
and get rid of the class building magic.

Regards,
Stephan
-- 
Stephan Richter
CBU Physics & Chemistry (B.S.) / Tufts Physics (Ph.D. student)
Web2k - Web Software Design, Development and Training


More information about the Zope3-users mailing list