[Zope] Testing document properties

Martijn Pieters mj@antraciet.nl
Wed, 20 Oct 1999 14:36:01 +0200


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')">

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
------------------------------------------