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

Luis De la Parra lparrab at gmx.net
Thu Aug 9 18:37:31 EDT 2007

Hi Darryl,

Darryl Cousins wrote:

> Fair call. I don't know either. The mars packages grew out a desire to
> replicate z3c.formdemo using grok/martian. Mars makes configuration more
> explicit than with vanilla grok and I doubt would ever be integrated
> into grok (partly also because the grok namespace would grow way to
> large with declarations and components).

I just had a look at it, and well... first of all I must confess I haven't
got the concept of viewlets/pagelets yet, and why you'd want to separate
the templates making a 3-registration process per page, but...

============== view.txt in mars.view:

  >>> layoutTemplate = os.path.join(temp_dir, 'layoutTemplate.pt')
  >>> open(layoutTemplate, 'w').write('''<div>My layout template</div>''')

  >>> class LayoutView(mars.view.LayoutView):
  ...     """This is the view class"""
  ...     grok.context(zope.interface.Interface)

  >>> class LayoutViewTemplate(mars.template.LayoutFactory):
  ...     """This is a template"""
  ...     grok.template(layoutTemplate)
  ...     grok.context(LayoutView)


I don't get what the purpose of the template-factorys is...I mean, what is
the advantage of registering the views/layouts in this way, instead of just

   class LayoutView(mars.view.Layout)

but if you were to write something like that, what would be the difference
to a  plain grok.View?
The same goes for the Pagelet... instead of having 

======mars.view / view.txt =========
  >>> class PageletView(mars.view.PageletView):
  ...     """This is the view class"""
  ...     grok.context(zope.interface.Interface)

  >>> class PageletViewLayout(mars.template.LayoutFactory):
  ...     """This the layout template looked up by the __call__ method of
  ...     grok.template(pageletTemplate)
  ...     grok.context(PageletView)

  >>> class PageletViewTemplate(mars.template.TemplateFactory):
  ...     """This the view template looked up by render method"""
  ...     grok.template(viewTemplate)
  ...     grok.context(PageletView)


why not just?

  class MyPagelet(mars.view.PageletView)
         mars.view.layout(pageletTemplate) # looked up on __call__()
         grok.template(viewTemplate)       # looked up by render()

..and again, grok.View provides  __call__, update, and render methods.

I think the difference must be in the interfaces for which they are
registered. ie, register the layout for "Interface" to get a common layout
for all views, and a view-specific "view-layout" (which would be
equivalent, but imho more elegant than the "normal way" of one template
only per view which calls standard_macros ) but from the examples I've seen
I haven't been able to figure it out. =(

cheers. luis

More information about the Grok-dev mailing list