[Zope] Could Someone Clean This DTML Up?
beno
zope@thewebsons.com
Mon, 06 Jan 2003 04:46:44 -0400
At 12:22 AM 1/6/2003 +0100, you wrote:
>beno schrieb:
>
>>Hi;
>>Here's my code. I know there are all sorts of errors. But I'm not sure
>>where in the documentation to find the corrections (other than somewhere
>>in the Zope Book). Your help would be appreciated.
>>
>><dtml-let lang="REQUEST.get('HTTP_ACCEPT_LANGUAGE')">
>> <dtml-in expr="context.objectsInTheFolder">
>> <dtml-if expr="&dtml-id==&dtml-lang">
>> <dtml-let approved="&dtml-lang">
>> <dtml-else>
>> <dtml-let approved="en-us">
>> </dtml-if>
>> </dtml-in>
>></dtml-let>
>
>First of all, terminate all &dtml entities by a semicolon.
>
>Second, dtml-let needs a closing tag. This tag can't be outside of the
>DTML hierarchy the opening tag is in, which means that if you define a
>variable inside of a dtml-if, you have to close it inside, too, and the
>value is lost for further use. Shortly: this won't work, try another way.
>
>Third, IMHO it doesn't make sense to extract values from variables inside
>a Python expression per DTML entities, try "id == lang" in line 3, and
>correct line 4 accordingly (your DTML namespace will be correctly looked
>up inside the expressions, you don't need the &dtml-...; part).
Okay, well here's what I've got right now...
<dtml-let lang="REQUEST.get('HTTP_ACCEPT_LANGUAGE')">
<dtml-in objectsInTheFolder>
<dtml-if id=="&dtml-lang;">
<dtml-let approved="&dtml-lang;">
<dtml-var approved>
</dtml-let>
<dtml-else>
<dtml-let approved="en">
<dtml-var approved>
</dtml-let>
</dtml-if>
</dtml-in>
</dtml-let>
If nothing else needs work, clearly line #2 does. How do I call the objects
in the folder? Also, strangely, whenever I try to save these changes in my
Zope it errors out with, of all things, HTTP 500. I tried to use a
<dtml-set> tag, which is a product I've installed, but it appears not to
work with 2.6. Without that tag, of course, I can't keep the variable from
going out-of-scope, so I have to work my magic within those nested
<dtml-let> tags, which I can do, although I (obviously) have to do it
twice, which is a bit of a kludge.
>Point four: would it be possible that this could be better done in a script?
Maybe. But if it can be done cleanly in DTML, that would be better because
this is mainly for a product that will hopefully serve as a tutorial for
newbies and a short DTML script would be appropriate (I have plenty of
short python scripts). How would I rewrite this line for a python script?
<dtml-let lang="REQUEST.get('HTTP_ACCEPT_LANGUAGE')">
TIA,
beno