RE: [Zope-dev] Rendering of objects in DTML
Bjorn Stabell wrote:
Hello,
When a content is rendered by the Zpublisher, its index_html() is called. When it is rendered in DTML, e.g., as <dtml-var content>, its __call__ method is called. The __call__ method is also called if the object appears in <dtml-if content> or <dtml-with content>. Is it possible to render these two cases differently from <dtml-var content>?
Which two cases? What do you mean by 'differently'?
cheers,
Chris
I would like <dtml-var content> <dtml-with content>... <dtml-if content> to call different functions. The first renders the object, the second returns a mapping of the content's attributes/properties, the third checks for "trueness" of the content. Rendering a content could be an expensive operation and I don't want to do it when doing dtml-with and dtml-if.
Bjorn Stabell wrote:
I would like
<dtml-var content> <dtml-with content>... <dtml-if content>
to call different functions. The first renders the object, the second returns a mapping of the content's attributes/properties, the third checks for "trueness" of the content. Rendering a content could be an expensive operation and I don't want to do it when doing dtml-with and dtml-if.
That kind of implicit weirdage is not something python encourages. <dtml-var content> ...should render <dtml-with "content.properties"> <dtml-if "content.true()"> ...is much better. cheers, Chris
On Tue, 2003-01-14 at 01:01, Bjorn Stabell wrote:
Bjorn Stabell wrote:
I would like
<dtml-var content> <dtml-with content>... <dtml-if content>
to call different functions. The first renders the object, the second returns a mapping of the content's attributes/properties, the third checks for "trueness" of the content. Rendering a content could be an expensive operation and I don't want to do it when doing dtml-with and dtml-if.
you can do that by having your object be non-callable (or returning self on __call__) and implementing __str__ where you can have access to the REQUEST thru self.REQUEST. <dtml-with content> works as expected because you're getting the object itself. To make <dtml-if content> work you should implement __len__ (if your object implements sequence or mapping, which it probably doesn't) or __nonzero__. Read the python docs for details on the implementation of these methods. Cheers, Leo -- Ideas don't stay in some minds very long because they don't like solitary confinement.
participants (3)
-
Bjorn Stabell -
Chris Withers -
Leonardo Rochael Almeida