[Grok-dev] grok.Layout and grok.Page

Paul Sephton prsephton at gmail.com
Fri Oct 16 10:22:50 CEST 2015


Hi;

I have been taking a closer look at the *grok.Layout* and *grok.Page* 
components, and have some queries.

 From what I can gather from the meager documentation, both 
/grok.Layout/ and /grok.Page/ subclass /grok.View/, and are a way to 
share a single layout view among many pages.

So, assuming

    class A(grok.Model):
        ...
    class B(grok.Model):
        ...

you can do

    class MyLayout(grok.Layout):
        grok.context(Interface)

and

    class AView(grok.Page)
        grok.context(A)
        grok.name('index')
        grok.layout(MyLayout)
        ...
    class BView(grok.Page)
        grok.context(B)
        grok.name('index')
        grok.layout(MyLayout)
        ...

and from what I can gather, when *AView *or *BView *are rendered, 
*MyLayer *will be rendered _*instead*_ of *AView* or *BView*. *AView 
*and *BView *have a *content()* method which returns their rendered 
content, so the layout can include the content in the rendered result.

In other words, when navigating to an instance of model *A*, the *AView* 
gets called, which renders *MyLayout*, which includes *AView.content()*.

Is that correct?  Do I have the right of it?

My real question is: what is the point of all this?  In my most probably 
limited understanding of what is going on, this looks like a really 
complicated way of achieving something you can achieve more simply and 
flexibly with other approaches, and I have to ask if this is true, what 
reason *grok.Layout* has for existing.

The way I would generally approach the above issue would be:

class IMyBasePage(Interface):
    ...

class Content(grok.ViewletManager):
    grok.context(IMyBasePage)

class A(grok.Model):
    grok.implements(IMyBasePage)
    ...

class B(grok.Model):
    grok.implements(IMyBasePage)
    ...

class AViewlet(grok.Viewlet):
    grok.context(A)
    grok.viewletmanager(Content)
    ...

class BViewlet(grok.Viewlet):
    grok.context(B)
    grok.viewletmanager(Content)
    ...

class Index(grok.View):  # My layout view
    grok.context(IMyBasePage)
    ...

With the above, when navigating to model *A* or model *B*, the Index 
view is rendered, which template renders the necessary page, including 
/*provider:content*/.  This /*provider:content*/ would be wither 
*AViewlet *or *BViewlet* depending on the actual context.

 From what I can tell, the difference between the /grok.Viewlet/ 
approach and the/grok.Layout/ approach is that /grok.Layout can 
reference at most a single sub view/ (the /grok.Page/), while using a 
Viewlet manager lets one use many content providers in the same 
template, and the index page can be designed more like an index template 
with a header section, a menu section, a content section, etc, etc.

Can someone please tell me what I am missing in all of this?  Is the 
*grok.Layout*  really so limiting?

Regards,
Paul


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.zope.org/pipermail/grok-dev/attachments/20151016/6a9097c6/attachment.html>


More information about the Grok-dev mailing list