[Zope-dev] Passing arguments to DTML Methods

Dieter Maurer dieter@handshake.de
Thu, 25 Jan 2001 22:53:20 +0100 (CET)


Espen Sorbye Frederiksen writes:
 > How do you pass on variables to a DTML Method.
 > If I would use a python method I would use <dtml-call "pythonmethod(var1,
 > var2)">. This does not work with DTML Methods. First of all why? Secondly
 > how is it possible to get around the problem?
DTML Methods have 2 positional and arbitrary many keyword parameters.
The positional arguments are "client" and "REQUEST".
"client" is an object (or tuple of objects or None).
All attributes of "client" are put into the DTML namespace.
"REQUEST" is a mapping object (or None), all keys of this
object are put into the DTML namespace.
All keyword arguments are put into the DTML namespace.

Thus, you can use:

      <dtml-XXX "method(_.None,_,param1=value1, param2=value2, ...)">

In this use: "_.None" is the client and "_" the mapping object.
You must pass the "_" as otherwise, you break the DTML namespace
chain.

An alternative, probably easier:

     <dtml-let param1="value1"
               param2="value2"
	       ....>
       <dtml-XXX method>
     </dtml-let>

i.e. you bring the arguments into the DTML namespace (with the "let")
and then let DTML automatically pass the namespace to your method.



Dieter