[Zope] indirect calling of methods with parameters

Bernd Worsch Bernd Worsch <bernd.worsch@frontsite.de>
Tue, 27 Mar 2001 19:05:43 +0200


On Tue, Mar 27, 2001 at 04:58:35PM -0800, sam gendler wrote:
> Bernd Worsch wrote:
> 
> > <dtml-let method="'ParaMethod(\'lalala\')'">
> >   <dtml-var "_[method]">
> > </dtml-let>
> >
> 
> I haven't used Zope in a while, but I believe that what you need is
> actually a combination of all of the things you have tried.  When you use
> dtml-var without quotes, the dtml interpreter lookes up the name that you
> have specified, and then calls that object if it is callable, otherwise it
> calls str() or repr() on it and inserts the results (I believe. I am
> guessing what really happens i an object is not callable.  It isn't
> relevant to this discussion, though).  Consequently, that object gets
> called without any parameters, since the var tag knows nothing about any
> parameter list, and there is obviously not an object named
> 'method(param1)', just an object named 'method'.
> 
> When you use the dtml-var tag with quotation marks inside, the dtml
> interpreter assumes the content between the quotes is a python expression,
> and executes it directly, within the current context.
> 
> Basically, <dtml-var method> is the the equivalent of <dtml-var
> name="method">. <dtml-var "method()"> is the equivalent of <dtml-var
> expr="method()">
> 
> You should be able to say <dtml-var "ParaMethod('lalala')"> to get your
> example above working.  Don't worry about the _[] syntax, which you don't
> need in this instance.  Assuming your method name doesn't have any
> characters that would be illegal in a python expression (such as '-', or
> any other operator), you can call it directly from teh var tag with the
> syntax I've shown you. Otherwise, you can use <dtml-var
> "_['para-method']('lalala')">
> 
> --sam
> 

Hi Sam and Thanks!

Your quite right and i've been hoping to find a useful blend of technics
for quite some time! I even reached the point of playing with an external
method giving me python's eval command. But as i needed to use some zope
objects this wasn't satisfactory either. 

Ok, getitem saved me for now, so i'm fine at the moment!

Thanks again!
Bernd 

-- 

-----Bernd Worsch-----------bernd.worsch@frontsite.de--------