<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
</head>
<body bgcolor="#FFFFFF" text="#000000">
Hi;<br>
<br>
I have been taking a closer look at the <b>grok.Layout</b> and <b>grok.Page</b>
components, and have some queries.<br>
<br>
From what I can gather from the meager documentation, both <i>grok.Layout</i>
and <i>grok.Page</i> subclass <i>grok.View</i>, and are a way to
share a single layout view among many pages. <br>
<br>
So, assuming<br>
<blockquote>
<pre>class A(grok.Model):
...
class B(grok.Model):
...</pre>
</blockquote>
you can do <br>
<blockquote>
<pre>class MyLayout(grok.Layout):
grok.context(Interface)</pre>
</blockquote>
and<br>
<blockquote>
<pre>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)
...
</pre>
</blockquote>
and from what I can gather, when <b>AView </b>or <b>BView </b>are
rendered, <b>MyLayer </b>will be rendered <u><b>instead</b></u>
of <b>AView</b> or <b>BView</b>. <b>AView </b>and <b>BView </b>have
a <b>content()</b> method which returns their rendered content, so
the layout can include the content in the rendered result. <br>
<br>
In other words, when navigating to an instance of model <b>A</b>,
the <b>AView</b> gets called, which renders <b>MyLayout</b>, which
includes <b>AView.content()</b>.<br>
<br>
Is that correct? Do I have the right of it?<br>
<br>
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 <b>grok.Layout</b> has for existing.<br>
<br>
The way I would generally approach the above issue would be:<br>
<pre>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)
...
</pre>
With the above, when navigating to model <b>A</b> or model <b>B</b>,
the Index view is rendered, which template renders the necessary
page, including <i><b>provider:content</b></i>. This <i><b>provider:content</b></i>
would be wither <b>AViewlet </b>or <b>BViewlet</b> depending on
the actual context. <br>
<br>
From what I can tell, the difference between the <i>grok.Viewlet</i>
approach and the<i> grok.Layout</i> approach is that <i>grok.Layout
can reference at most a single sub view</i> (the <i>grok.Page</i>),
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.<br>
<br>
Can someone please tell me what I am missing in all of this? Is the
<b>grok.Layout</b> really so limiting?<br>
<br>
Regards,<br>
Paul<br>
<br>
<br>
</body>
</html>