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

Darryl Cousins darryl at darrylcousins.net.nz
Thu Aug 16 01:12:12 EDT 2007


Hi Luis

On Wed, 2007-08-15 at 18:45 +0200, Luis De la Parra wrote:
> 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):
>         grok.context(interface.Interface)
>         grok.template('site_layout.pt')
> 
> #
> 
> 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):
>         grok.name('index.html')
>         grok.context(Contact)
> 
>         def helper_method_for_my_view(self):
>                 pass
> 
> class ContactTemplate(mars.template.TemplateFactory):
>         grok.template('contact.pt')
>         grok.context(ContactPagelet)
> ##
> 
> 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...

Yes. Sorry I didn't read this correctly before my last post. My bad.

That's right. And yes, you could override ``render`` in the view class
to return whatever you like. (Which isn't quite the same as 'if render
not defined'.)

Just another point about z3c.pagelet. You don't only need to define:

<tal:block replace="structure provider:pagelet">

in the layout template. The provider then looks up the IPageletView
(this with mars is a mars.view.PageletView) and renders the ``render``
method into the layout.

Regards,
Darryl



More information about the Grok-dev mailing list