[Zope] Could Someone Clean This DTML Up?

Jaroslav Lukesh lsh@wo.cz
Mon, 6 Jan 2003 14:28:55 -0000


| Odes=EDlatel: Martin Gebert <Murphy@members.netsolution-net.de>
| > <dtml-let lang=3D"REQUEST.get('HTTP_ACCEPT_LANGUAGE')">
| >  <dtml-in expr=3D"context.objectsInTheFolder">
| >   <dtml-if expr=3D"&dtml-id=3D=3D&dtml-lang">
| >    <dtml-let approved=3D"&dtml-lang">
| >   <dtml-else>
| >    <dtml-let approved=3D"en-us">
| >   </dtml-if>
| >  </dtml-in>
| > </dtml-let>=20
|=20
| First of all, terminate all &dtml entities by a semicolon.
|=20
| Second, dtml-let needs a closing tag. This tag can't be outside of the=20
| DTML hierarchy the opening tag is in, which means that if you define a=20
| variable inside of a dtml-if, you have to close it inside, too, and the=
=20
| value is lost for further use. Shortly: this won't work, try another wa=
y.
|=20
| Third, IMHO it doesn't make sense to extract values from variables=20
| inside a Python expression per DTML entities, try "id =3D=3D lang" in l=
ine=20
| 3, and correct line 4 accordingly (your DTML namespace will be correctl=
y=20
| looked up inside the expressions, you don't need the &dtml-...; part).
|=20
| Point four: would it be possible that this could be better done in a
script?

DTML:

<dtml-let lang=3D"REQUEST.get('HTTP_ACCEPT_LANGUAGE')">
  <dtml-in expr=3D"context.objectsInTheFolder">
   <dtml-if expr=3D"&dtml-id=3D=3D&dtml-lang">
    <dtml-call "REQUEST.set('approved', ['lang'])">
   <dtml-else>
    <dtml-call "REQUEST.set('approved', 'en-us')">
   </dtml-if>
  </dtml-in>
</dtml-let>

Regards JL.