[Zope-dev] Rendering of objects in DTML

Bjorn Stabell bjorn@exoweb.net
Wed, 15 Jan 2003 16:00:15 +0800


Thanks Leo, this is very helpful.  It should probably be in a HOWTO
somewhere. :)

> -----Original Message-----
> From: Leonardo Rochael Almeida [mailto:leo@hiper.com.br]=20
>=20
> On Tue, 2003-01-14 at 01:01, Bjorn Stabell wrote:
> > > Bjorn Stabell wrote:
> >=20
> > I would like
> >=20
> >   <dtml-var content>
> >   <dtml-with content>...
> >   <dtml-if content>
> >=20
> > to call different functions.  The first renders the object,=20
> the second=20
> > returns a mapping of the content's attributes/properties, the third=20
> > checks for "trueness" of the content.  Rendering a content=20
> could be an=20
> > expensive operation and I don't want to do it when doing=20
> dtml-with and=20
> > dtml-if.
>=20
>=20
> you can do that by having your object be non-callable (or=20
> returning self on __call__) and implementing __str__ where=20
> you can have access to the REQUEST thru self.REQUEST.=20
> <dtml-with content> works as expected because you're getting=20
> the object itself. To make <dtml-if content> work you should=20
> implement __len__ (if your object implements sequence or=20
> mapping, which it probably doesn't) or __nonzero__. Read the=20
> python docs for details on the implementation of these methods.
>=20
> 	Cheers, Leo
>=20
> --=20
> Ideas don't stay in some minds very long because they don't=20
> like solitary confinement.