[ZDP] BackTalk to Document The Zope Book (2.5 Edition)/Using Zope Page Templates
nobody@nowhere.com
nobody@nowhere.com
Fri, 06 Sep 2002 20:53:34 -0400
A comment to the paragraph below was recently added via http://www.zope.org/Documentation/Books/ZopeBook/current/ZPT.stx#2-97
---------------
In general Zope supports content, presentation, and logic
components. Page Templates are presentation components and they
can be used to display content components.
% Anonymous User - Aug. 3, 2002 5:25 am:
I thought the whole point of page templates was to apply them to content for rendering. Surely then this
deserves more coverage than two lines at the bottom of the chapter. It took me days to even work out how you
applied a template to content objects, and as for how to make the default rendering of an object be through a
template, or how to prevent display of a content object unless it's through a template, well that's got me
stumped.
% Anonymous User - Sep. 6, 2002 8:53 pm:
To apply a template to a content object, view the template in the context of the
object. e.g. visit the url my_object/my_template. The template will then be
able to access any of the object's attributes like <div tal:replace="here/some_property_or_method" />. For
example, you could view a CMF Document through a page template by having code like <div
tal:replace="here/cookedBody" /> in the template.
Your other questions are trickier. TO make the default rendering of an object be through a template: well,
what kind of object? Folders of course you can do by defining index_html as a template; custom Zope products
you can do likewise. But for callable objects like DTML Methods, you can't force it to render itself through
a template, except (again) by calling the template in the context of the doc. You could access the object's
entire content in the template like <div tal:replace="python:here()" />.
I don't know how you'd "prevent display of a content object unless it's through a template". I was going to
suggest proxy roles, but templates don't have proxy roles.