[Grok-dev] Alternative Layout System in Grok with z3c.template/z3c.pagelet

Christian Klinger cklinger at novareto.de
Wed Mar 18 05:12:37 EDT 2009


Hello,

i worked on a prototype (megrok.pagelet) for integrating
z3c.template and z3c.pagelet in grok.

This is a short summary what?s the current status of
megrok.pagelt:

MEGROK PAGELET
==============

This package try to bring the functionality of z3c.template and
z3c.pagelet to grok.

z3c.template gives us a alternative for the zpt:metal based layouts in 
grok. The z3c.pagelet has the advantage that it?s possible to register 
layouts with help of the zope-component-architecuture. This allows you 
to change or modify layouts without touching the original *master* macro.

This means you get a megrok.pagelet.Layout component which holds
the Layout. Instead of using grok.View you have to take
megrok.pagelet.Pagelet for normal BrowserViews. This is surely something
we have to discuss. I think it should be possible to bring this 
functionality to grokcore.View.

If you need more information about z3c.template please look here [1].



The Layout
----------

The first thing we have to do is set up a Layout for our pagelet.

class MyLayout(megrok.pagelet.Layout):
     grok.context()
     grok.layer()

     megrok.pagelet.template('my_layout_template.pt')

This configures the template ('my_layout_template.pt') as a layout for 
the given context and layer. Of course it?s possible to specify 
different layouts for different layers or contexts.


In the content of my_layout_template.pt is something like this:

<html>
  <body>
    <div class="layout" tal:content="structure view/render">
          here comes the content
    </div>
  </body>
</html>


The Pagelt (View)
-----------------

Ok instead of using the common grok.View for our BrowserViews we now use
megrok.pagelet.Paglet. This component has one difference to a normal
grok.View. This difference is in the __call__ method of the 
megrok.pagelet.Pagelet.

This means that the  __call__ method of a  Pagelet does not only return 
the renderd "template" of the Pagelet. The __call__ method first 
searches for the layout in given context and layer and then it renders 
the "template" in this layout.

class View(megrok.pagelet.Pagelet)
     grok.context()
     grok.layer()
     grok.name()

     def render(self)
         return "..."



You can find megrok.pagelet in my svn.zope.org Sandbox. [2]

We had already some discussions on this topic. Please take a look on
this post for more info. [3]


Please see this as a starting point for further investigations.
Maybe someone can have a look and provide some feedback.


Christian

[1] http://pypi.python.org/pypi/z3c.template/
[2] 
http://svn.zope.org/Sandbox/cklinger/megrok.pagelet/trunk/src/megrok/pagelet/
[3] 
http://article.gmane.org/gmane.comp.web.zope.grok.devel/7289/match=megrok+pagelet



More information about the Grok-dev mailing list