[Zope] In DTML, no cookie then default. How?

Blandford, Simon [BSS Audio UK] Simon.Blandford@bss.co.uk
Wed, 20 Jun 2001 14:40:19 +0100


Hi Phil,

Yup that works!

I just added
<dtml-unless "REQUEST.has_key('batch_size')">
	<dtml-call "RESPONSE.setCookie('batch_size', 20)">
</dtml-unless>

to the index_html document.

Thanks for the tip,

Regards,
Simon B.

P.S.
Sorry for sending in HTML last time.


> -----Original Message-----
> From: Phil Harris [mailto:phil.harris@zope.co.uk]
> Sent: 20 June 2001 14:25
> To: Blandford, Simon [BSS Audio UK]; zope@zope.org
> Subject: Re: [Zope] In DTML, no cookie then default. How?
> 
> 
> Simon,
> 
> try something like (untested):
> 
> <dtml-unless thing_cookie>
> <dtml-call "REQUEST.set('thing_cookie','default value for the 
> cookie')">
> </dtml-unless>
> 
> You may need to change the unless stuff, to something like 
> <dtml-unless
> "REQUEST.cookies.has_key('thing_cookie')">, or similar.
> 
> hth
> 
> Phil
> phil.harris@zope.co.uk
> 
> ----- Original Message -----
> From: Blandford, Simon [BSS Audio UK]
> To: 'zope@zope.org'
> Sent: Wednesday, June 20, 2001 2:10 PM
> Subject: [Zope] In DTML, no cookie then default. How?
> 
> 
> Hi,
> 
> I have worked out how to store cookies and retreive them in 
> DTML to store
> preferences on a form.
> 
> Question.
> If the cookie isn't there yet or gets deleted/rejected etc. 
> How do I insert
> a default value into the name space?
> 
> What I need is something like...
> if <thing> isn't there then <thing>=some default value.
> 
> What would solve my problems would be if <dtml-let> didn't 
> need a closing
> </dtml-let>.
> 
> Background...
> 
> This cookie is used to enter a preference value in a form, thus...
> 
>  <tr>
>   <th align="left">Batch Size</th>
>   <td><input type='integer' name='batch_size:int' size=2
>    value="&dtml.missing-batch_size;" /></td>
>  </tr>
> 
> When the form is entered the cookie is set to the value 
> inserted by the
> user, thus...
> <dtml-if "REQUEST.has_key('batch_size')">
>  <dtml-call "RESPONSE.setCookie('batch_size', batch_size, 
> expires='Wed, 19
> Feb 2020 14:28:00 GMT')">
> </dtml-if>
> 
> When the user comes back to the form, the value of batch_size 
> is magically
> read from the cookie as a default again.
> 
> Problem...
> The form is called for the first time so there is no cookie. 
> How do I set
> batch_size to a default value?
> 
> Regards,
> Simon.
> 
> 
> 
> 
>