[ZPT] Nesting templates
Clemens Robbenhaar
zpt@zope.org
Thu, 21 Nov 2002 21:01:45 +0100
Hi Max,
[...]
> My basic idea is to build a site wich would have the following basic
> properties
>
> 1. Dynamic navigation
> 2. Master template through which all content is fetched
>
> I've been trying to do this by doing a sturcture like this:
>
> site_root/index_html
> Site master template
>
> site_root/content
> Folder with all content, as page templates, containing just the content, no
> reference to the master template. This folder is indexed by the navigation.
> Any special case functionality can then be put in the root.
>
> Then I've been trying to create a script to fetch the correct content and
> display it. I realize some feel that templates are not content or that I
> should use CMF, but I want to build something from the ground up to learn.
>
> I've been trying to get the master template to include the nested content
> template by using a tal:content="structure ..." type of syntax, but it seems
> that this only works when I statically try to give the path to the content.
> I've been looking all over the web for a proper spec on how this
> "structure"-keyword is suppose to work, but haven't really found anything.
>
About the 'structure' keyword: maybe look at
http://www.zope.org/Documentation/Books/ZopeBook/current/AppendixC.stx
(though it is a little hard to find the place where it is explained that
it renders the value without escaping '<', '>', '&' ...)
Thus it dies not have a lot to to with Your problem, except that You
most proabaly want to use it ;-)
> So really my question comes down to: how do I nest a template? Should I even
> be doing this?
You can do this, if this home grown design/content separation is just
good enough for You. However You do not give an example how the content
is selected ... I assume the id of the "content" page template to be
rendered is passed as request-parameter 'content_id'; e.g. if this is
'foo', You want to include /site_root/content/foo in Yout index_html.
The dynamic lookup should go via the 'getattr' helper function, e.g.
<span tal:define="content_page python:getattr(here.content, request['foo'])"
tal:replace="structure content_page" />
If the lookup is more complex (e.g. You might want some error handling,)
its better done by a script called from the 'index_html'. Well, it seems
You are already doing this, if I understand correctly ...
>
> CMF I don't wish to use at the moment though. Too complex and too rigid for
> my taste. I've looked at Kubes, but they looked too much like a kludge.
I guess the developers of these products will appreciate Your subtle
and informed comments very much ;->
Cheers,
Clemens