[Grok-dev] Re: Sharing a common template layout?
Philipp von Weitershausen
philipp at weitershausen.de
Thu Jan 18 10:22:52 EST 2007
Kevin Teague wrote:
> Is there a Grok way to share a common template layout?
>
> I looked at the Grok Wiki application, which has a
> 'page_templates/layout.pt' which is used by both the
> 'page_templates/edit.pt' and 'page_templates/index.pt' templates.
> However, if grokwiki added an Image grok.Model for example, it would
> require repeating the layout in 'image_templates/layout.pt'. Which
> obviously isn't the right way to go about it - but I am not sure what
> the right way to do it is ... any pointers would be much appreciated.
Here's what I would do:
1. Put 'layout.pt' in some foo_templates directory.
2. Then in the corresponding foo.py module, create a Layout view:
class Layout(grok.View):
grok.context(zope.interface.Interface) # applies to all objects
This would get the 'layout' view registered for all objects (and not
just the model in foo.py) and you could use it via
'obj/@@layout/<macro>' in all Page Templates.
If you happen to have a lot of such layout-specific things, it might
make sense to put this into a separate, say, 'layout.py' module.
--
http://worldcookery.com -- Professional Zope documentation and training
2nd edition of Web Component Development with Zope 3 is now shipping!
More information about the Grok-dev
mailing list