[Zope] dtml-if and checkboxes

Charlie Reiman creiman@kefta.com
Fri, 4 Oct 2002 14:08:32 -0700


> -----Original Message-----
> From: zope-admin@zope.org [mailto:zope-admin@zope.org]On Behalf Of
> Passin, Tom
> Sent: Friday, October 04, 2002 1:46 PM
> To: zope@zope.org
> Subject: RE: [Zope] dtml-if and checkboxes
>
>
> [Meilicke, Scott]
> >
> > <dtml-if check_box>
> >
> > <dtml-if expr="check_box == ('on')">
> > The check box is checked!
> > </dtml-if>
> >
> > </dtml-if>
> >
> > The above should work, but there may be a better way... Maybe
> > something like <dtml-if "check_box and check_box == ('on')">,
> > not sure though.
>
> No, because if the checkbox is not checked then there will be no such
> variable in the REQUEST, so the if test will fail.  This is how forms
> work, as Jim Penny just said.  You have to check for the existence of
> the variable by name.
>
> Cheers,
>
> Tom P

Actually, this will work although it is wordy. <dtml-if somevar> is special
and will evaluate to false if somevar is not defined. This is very different
from <dtml-if "somevar"> which will throw and exception if somevar is not
defined.

Having said that, using has_key is a lot cleaner.