[Zope] dtml methods and dictionaries
Tres Seaver
tseaver@palladion.com
Tue, 18 Jan 2000 17:09:22 -0600
Evan Simpson <evan@4-am.com> wrote:
>
> Philip Corp wrote:
>
> > I need to write a dtml method which calls an external method, which
> > returns a dictionary, and have the dtml method lookup and use keys and
> > values from the dictionary. Is this even possible? If so how? I am
> > completely stuck! I would really appreciate any help with this. Thanks.
>
> Just off the top of my head (untested!) the following sort of thing should
> work:
>
> def AnExtMeth():
> return {1: 'one', 2: 'two', 3: 'three'}
>
> <dtml-let dict="AnExtMeth()">
> <dtml-in expr="dict.items()">
> &dtml-sequence-key; &dtml-sequence-item;
> </dtml-in>
> 1: <dtml-var expr="dict[1]">
> </dtml-let>
>
> or <dtml-call expr="REQUEST.set('dict', AnExtMeth())"> to make the
> dictionary generally available.
Or for even *more* twisted fun:
<dtml-call expr="REQUEST.other.update( AnExMeth() )">
sucks each key/value pair into the "default" namespace.
Can-you-say-"pollution"?-I-knew-you-could'ly,
Tres.
--
=========================================================
Tres Seaver tseaver@palladion.com 713-523-6582
Palladion Software http://www.palladion.com