[Zope-dev] Asking for the type of a variable

Loren Stafford lstafford@icompression.com
Tue, 9 Nov 1999 14:14:47 -0800


You need to look at: http://www.zope.org/Members/Zen/howto/FormVariableTypes

Use :list to make your form field a list, no matter how many entries it has.

-- Loren

> -----Original Message-----
> From: zope-dev-admin@zope.org [mailto:zope-dev-admin@zope.org]On Behalf
> Of David S. Harrison
> Sent: Tuesday, November 09, 1999 13:55
> To: zope-dev@zope.org
> Subject: [Zope-dev] Asking for the type of a variable
>
>
>
> It looks like I need to ask for the type of a python variable from DTML.
> So far, I haven't been able to get this to work:
>
>   <dtml-if "type(TAG)==type('x')">
>
> I am trying to see if the TAG variable is a string.  Zope complains about
> "type".  I tried using the special name space:
>
>   <dtml-if "_.type(TAG)==_.type('x')">
>
> But it looks like "type" is not a function available through that means.
> Is there another way to use the type of a variable for branching?
>
> Actually, the reason this arises is forms.  I have a series of radio
> buttons in a form.  When submitted to Zope, I notice that if one item
> is selected, the value is a string.  When many items are selected,
> the value is a list of strings.  Since <dtml-in> does not accept a
> single string as an argument, I need to test to see if the incoming
> value is a string or a list of strings before processing it.  I will
> gladly accept any better idioms for handling this case.  The tests
> certainly make the DTML code more complex than I think it should be.
>
> 				David S. Harrison
> 				(dsh@magma-da.com)
>