[Zope-dev] Rendering of objects in DTML

Leonardo Rochael Almeida leo@hiper.com.br
16 Jan 2003 18:13:12 -0200


For the record, by following the same pattern it should be possible to
implement a class that responds to <dtml-in content> too, by
implementing __getitem__

On Wed, 2003-01-15 at 06:00, Bjorn Stabell wrote:
> 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] 
> > 
> > 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.
> 
> _______________________________________________
> Zope-Dev maillist  -  Zope-Dev@zope.org
> http://lists.zope.org/mailman/listinfo/zope-dev
> **  No cross posts or HTML encoding!  **
> (Related lists - 
>  http://lists.zope.org/mailman/listinfo/zope-announce
>  http://lists.zope.org/mailman/listinfo/zope )
> 
-- 
Ideas don't stay in some minds very long because they don't like
solitary confinement.