From: zope-bounces@zope.org [mailto:zope-bounces@zope.org] On Behalf Of Maik Jablonski Jianping Zhu wrote:
I in a file i have code like this: <dtml-if "teach=='y'"> <dtml-let t="'Yes'"></dtml-let> <dtml-else> <dtml-let t="'No'"></dtml-let> </dtml-if>
I want to access varible t outside this if loop how can i declear it global to the entire file?
Use the REQUEST-Object to store "global" variables for current page-request:
<dtml-if "teach=='y'"> <dtml-call "REQUEST.set('t','Yes')"> <dtml-else> <dtml-call "REQUEST.set('t','No')"> </dtml-if>
Or you can wrap the page in a dtml-let statement that assigns t, like this - <dtml-let t="(teach=='y' and 'Yes') or (teach=='n' and 'No')"> ... </dtml-let> This way you get the assignment in one fell swoop, and you avoid adding a variable to the REQUEST, which is always a good thing. How did I know that this construction would work? It's one of the nice things about Python syntax (you can do nearly the same thing in javascript, too). Cheers, Tom P