[Zope] Keeping a Variable's Value: This SHOULD Be Easy

Tom Jenkins tjenkins@devis.com
30 Oct 2001 15:00:39 -0500


On Tue, 2001-10-30 at 14:38, Ben Ocean wrote:
> OOPS! Correction...
> 
> ...but apparently it's not. If I were writing this in PHP:
> 
> <html><body>
> Okay, boys and girls! Let's open the magic box and generate a random 
> number! (applause)<br and drum roll>
> <? x = int mt_rand(0,9); echo x ?><br, strike up the band>
> Wow! Wasn't that exciting? Oh no! I forgot the magic number<br, shrieks of 
> horror>
> <? echo x ?><br, strike up the band again> Oh, of course! How could I 
> forget!<br, fade to black>
> </body></html>
> 
> ...but apparently DTML *does* forget. Call that daggone variable more than 
> once and you have to run the formula that generates a random digit! Bam! 
> Variable's gone. Is there no way around this?
> Please help...
> BenO
> 

if you put the result in the REQUEST object you can reference it other
places.

<dtml-call expr="REQUEST.set('x', _.random.randint(0,9))">
my random number is = <dtml-var x>
....
my random number is still = <dtml-var x>

-- 

Tom Jenkins
Development InfoStructure
http://www.devis.com