[Zope] Testing document properties

Rafael Cordones Marcos rcm@bcnartdirecte.com
Wed, 20 Oct 1999 23:47:14 +0200


On Wed, Oct 20, 1999 at 02:36:01PM +0200, Martijn Pieters wrote:
> At 12:24 20/10/99 , Rafael Cordones Marcos wrote:
> >Hi,
> >
> >I have several DTML Doc named "caso" each of them in a diferent
> >directory.
> >Two of these "caso" documents have a property called "idioma" with
> >type string and value "en". The others do not have this property.
> >
> >In the parent directory I have another document in which I want to
> >check this property *when* available. So I do:
> >
> ><dtml-if caso.idioma>
> >   <dtml-if "caso.idioma == 'en'">
> >     <h2>What is your diagnosis?</h2>
> >   <dtml-else>
> >     <h2>¿Cual es su diagnóstico?</h2>
> >   </dtml-if>
> ><dtml-else>
> >   <h2>¿Cual es su diagnóstico?</h2>  <****
> ></dtml-if>
> >
> >I want to test if this property exists. If it exists and its value is
> >"en" then print a text in English. Otherwise print it in Spanish.
> >The above DTML code always returns the text marked with "<****".
> >I've tried puttin the first if in double quotes like <dtml-if
> >"caso.idioma"> but it fails when the document does not have this
> >property.
> 
> That's because <dtml-if caso.idioma> tests for the availability of the 
> property "caso.idioma", including the dot. You want something like:
> 
>    <dtml-if "hasattr(caso, 'idioma')">

This did not work. But <dtml-if "_.hasattr(caso, 'idioma')"> did!

Thanx!

Rafa
 
> which will test for the existence of the idioma property on the caso object.
> 
> --
> Martijn Pieters, Web Developer
> | Antraciet http://www.antraciet.nl
> | Tel: +31-35-7502100 Fax: +31-35-7502111
> | mailto:mj@antraciet.nl http://www.antraciet.nl/~mj
> | PGP: http://wwwkeys.nl.pgp.net:11371/pks/lookup?op=get&search=0xA8A32149
> ------------------------------------------
> 
> _______________________________________________
> Zope maillist  -  Zope@zope.org
> http://www.zope.org/mailman/listinfo/zope
> 
> (Related lists - please, no cross posts or HTML encoding!
> 
> To receive general Zope announcements, see:
> http://www.zope.org/mailman/listinfo/zope-announce
> 
> For developer-specific issues, zope-dev@zope.org -
> http://www.zope.org/mailman/listinfo/zope-dev )

-- 
Linux. The Choice of a GNU Generation! -> http://www.debian.org