[Grok-dev] documentation issue wrt megrok.layout

Souheil CHELFOUH trollfot at gmail.com
Tue Mar 30 13:29:20 EDT 2010


The concept of "layout" is about the same than the "pagelet" concept.
The idea is that your views are not responsible for the rendering of
the whole page, but only for the rendering of the "body" of the page.
These views are called "Page" and they delegate the rendering of the
"decoration" to a layout object.
It allows you , when using a Page, to chose whether you'll render just
or the entire page (layout + body).
It's very handy when you want a pluggable and/or reusable layout.
Pages' code become much simplier.
It's very cool for ajax calls too, so you can render only what you
need to replace HTML bits.
It has lots of avantages. It's not like viewletmanagers and viewlets.
These approaches are complementary.

2010/3/30 Roger Erens <roger.erens at e-s-c.biz>:
> Thanks for explaining. Souheil.
>
> While we're at it, could you also explain when to use megrok.layout
> and when to use viewlets inside viewletmanagers that are placed in a
> main template? Or is this documented somewhere? The pypi page of
> megrok.layout is more about the 'how' and not so much about the
> 'why'...
>
> Cheers,
>
> Roger
>
> On Tue, Mar 30, 2010 at 14:43, Souheil CHELFOUH <trollfot at gmail.com> wrote:
>> Hello,
>>
>> The readme of megrok.layout is indeed very synthetic.
>> The grok_component is declaring in the globals of the testing machinery.
>> It comes from : grokcore.component.testing
>>
>> It's not detailed because this process is done at start time by Grok, normally.
>>
>> 2010/3/30 Roger Erens <roger.erens at e-s-c.biz>:
>>> Hi,
>>>
>>> in a Grokv1.0 project I start up bin/python-console and execute the
>>> commands as found on
>>> http://pypi.python.org/pypi/megrok.layout:
>>>
>>>    >>> from megrok.layout import Layout
>>>    >>> from zope.interface import Interface
>>>    >>> import grokcore.component as grok
>>>    >>> class MyLayout(Layout):
>>>    ...     grok.name('mylayout')
>>>    ...     grok.context(Interface)
>>>    ...
>>>    ...     def render(self):
>>>    ...         return u"a simple layout"
>>>
>>> We grok our component:
>>>
>>>    >>> grok_component('MyLayout', MyLayout)
>>>    True
>>>
>>> But I don't get True as a result but:
>>>
>>> Traceback (most recent call last):
>>>  File "<console>", line 1, in <module>
>>> NameError: name 'grok_component' is not defined
>>>
>>> I'm still too much of a newbie to know what 'grokking our component'
>>> is supposed to do, therefore:
>>>
>>> what should be used instead of :func:`grok_component()`? Or do I need
>>> to import something else, too?
>>>
>>> Cheers,
>>>
>>> Roger
>>> _______________________________________________
>>> Grok-dev mailing list
>>> Grok-dev at zope.org
>>> https://mail.zope.org/mailman/listinfo/grok-dev
>>>
>>
>>
>


More information about the Grok-dev mailing list