[Zope] indirect calling of methods with parameters

Casey Duncan cduncan@kaivo.com
Tue, 27 Mar 2001 09:23:53 -0700


Bernd Worsch wrote:
> 
> Sorry, but this is above me head!
> 
> I'm trying to call a method that needs parameters indirectly. Well,
> after reading some docs i believe to somehow understand how
> indirect calling of variables works. What's more, everything is fine
> when no parameters are involved:
> 
> <dtml-let method="SomeMethod">
>   <dtml-var method>
> </dtml-let>
> 
> <dtml-let method="'SomeMethod'">
>   <dtml-var "_[methode]">
> </dtml-let>
> 
> Both Variants call SomeMethod, which is fine! On the other hand
> i'm totally lost when parameters are involved.
> 
> I for example tried to build my commandcall as a string. But using
> _[] won't work as it naturally won't call the method but look for
> an object with a kind of unusal name, which doesn't exist. It seems
> like i need some kind of eval construct. Any suggestions?
> 
> Or for short: How do i change the following code to call method instead
> of giving me an KeyError on the object named ParaMethod('lalala') ?
> 
> <dtml-let method="'ParaMethod(\'lalala\')'">
>   <dtml-var "_[method]">
> </dtml-let>
> 
> Thanks
> Bernd
> 
> --

_[name] does a name lookup as you have found. You cannot pass parameters
directly through _[name] though. If you wanted to pass some parameters
to an arbitrary method you could do:

<dtml-var expr="_.getitem(method)(params)">

If you wanted the parameter list to be variable as well, you could try
passing a dictionary like so:

<dtml-let params="{'arg1':value1, 'arg2':value2, ...}">
    <dtml-var expr="_.getitem(method)(kw=params)">
</dtml-let>

The params dictionary could be set anywhere before the actual call or
even passed whole as a parameter to the calling method.
-- 
| Casey Duncan
| Kaivo, Inc.
| cduncan@kaivo.com
`------------------>