[Zope] Re: global varible to files

Passin, Tom tpassin at mitretek.org
Fri May 14 12:14:52 EDT 2004


> From: zope-bounces at zope.org [mailto:zope-bounces at 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



More information about the Zope mailing list