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

1 view
Skip to first unread message

Paul Sephton

unread,
Oct 16, 2015, 4:51:22 AM10/16/15
to Grok Development
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 BViewAView 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


Christopher Lozinski

unread,
Oct 20, 2015, 2:14:27 PM10/20/15
to Paul Sephton, Grok Development
Sorry for taking so long to respond. I was at the Plone conference.

I am using grok.layout.

And yes it calls a content method.

I did not realize that i could use the command:

grok.layout(aLayout).

I do not like grok.layout. Just was painful to use. It is not the
model for user interfaces that I want to use.

I have page templates, I edit them through the web. They can acquire
viewlets.

You have a different approach. A very python centric point of view. If
that is your point of view, go with it. Grok is
pretty agnostic. It will let you do whatever you want with views.

I hope that helps.
Chris







On 10/16/15 10:22 AM, Paul Sephton wrote:
> Is that correct? Do I have the right of it?


_______________________________________________
Grok-dev mailing list
Grok...@zope.org
https://mail.zope.org/mailman/listinfo/grok-dev

Souheil CHELFOUH

unread,
Oct 20, 2015, 5:26:37 PM10/20/15
to Christopher Lozinski, Grok Development, Paul Sephton
Hello there Paul,

i'm one of the developers of grok.layout, so maybe I can share some insights.
I've been away from grok for a while, but I'm still using that concept in my python projects.

Viewlets and Layouts are not mutually exclusive, they are both tools to compose a renderable view.
A layout is, as its name indicates, a way to organise your content, globally.
The Layout doesn't hijack the managers, it still renders them, since the TAL processor uses the 'view' variable of the template namespace to lookup the managers and viewlet components.
The Layout can be used to radically alter the global rending of a site, but also the managers called.
A Page is the core of what needs to be rendered for a given context, without the whole html heavy load, without the contextual viewlets and components coating, making it easy to aggregate them.
Since Layouts register on a layer, they can be a mean to skin your site easily.

This concept exists in Zope3 for a while, under the name Pagelet (https://pypi.python.org/pypi/z3c.pagelet). It was merely simplified for grok.






Reply all
Reply to author
Forward
0 new messages