[Grok-dev] Re: Re: Re: viewlets, pagelets and friends

Luis De la Parra lparrab at gmx.net
Wed Aug 15 12:45:42 EDT 2007

hi again,

Darryl Cousins wrote:
> The use of the pagelet concept makes it imperiative to be able to define
> which interface the registered template provides (usually IPageTemplate or
> ILayoutTemplate) and also to be able to define a name (possible required
> by a view) and thirdly to be able to define the macro to be used from
> within the template (introducing `z3c.macro`_).
> For these reasons the  ``grok.template`` has been reinvented in
> `mars.view`_ to tell the grokker that the view should look up a named
> template. And templates are now registered as any other component using
> grokkers. The difference being that the component class is a factory - and
> therefore named as such.
> A template is not bound to a view as an attribute. Instead the view will
> look up a template in the component registry, a template can then be
> easily reused by many views (as layout templates usually are) and a view
> can be created to look up as many templates as it may require (by name or
> interface depending on design and needs).

I think I'm starting to get it (finally!) =)

so I can imagine to have something like:

### general layout for my site ###

class SiteLayout(mars.template.LayoutFactory):


so that registers a template which "provides" ILayout and can be found for
every view/context.

then I would have
class Contact(grok.Model):
        name = ""
        email = ""

class ContactPagelet(mars.view.PageletView):

        def helper_method_for_my_view(self):

class ContactTemplate(mars.template.TemplateFactory):

the pagelet would look up the layout template and find the SiteLayout, 
then, if "render" is not defined, it would look up a template implementing
IPageTemplate (ContactTemplate) and render it...

just a few questions: 
1)do PageTemplates ever provide some extra functionality, or do they
always "only" render the template file?
2)Are not PageletViews more or less "hard-wired" to a given template? (a
template can be used from several pagelets, but a pagelet can only use one

if those two are correct, I think having to create an extra class for the
template registration is only boiler-plate code that's not really

I patched the "Pagelet Grokker" locally in meta.py in mars.view to register
a template providing IPageTemplate if the grok.template declaration is
used, so that I can replace the code above for :

class ContactPagelet(mars.view.PageletView):

        def helper_method_for_my_view(self):

and seems to have exactly the same effect as with the two classes... am I
missing something here/losing "flexibility" or whatever that I might need
at a later time?

I also think the pageletgrokker should ensure that a template is registred
for the pagelet OR it defines a render method, but not both. I don't know
if such a check would fit in mars or if it would be more grok-like.

regards. luis

More information about the Grok-dev mailing list