[Zope-dev] Passing arguments to DTML Methods

Jon Franz jfranz@one.net
Fri, 26 Jan 2001 14:06:58 -0500


This is an undocumented (afaik) feature of DTML methods/documents - due to
the way python
argument mapping works, you can pass any value into a 'local' variable in a
DTML method like thus:

<dtml-var "myDTMLmethod(foo=5,greg=Sally)">

this the above case, Sally could be a legal variable value that will be put
into the new local greg
in your DTML method, and one named foo with the value of 5.  AFAIK this is
pass-by-value, so modifying greg in your called method will not change
sally, but I could be wrong...
I use this sort of thing quite often in one of my ongoing projects where I
need to reformat
dates strings from their mysql format to how the client wants to view
them... I have a method named
undb_dateout that uses a variable called 'dbdate' and does some string
splitting and formatting to output it.
Originally, I would do things like this with the method:

<dtml-call "REQUEST.set('dbdate', currentdatevar)">
<dtml-var undb_dateout>

Then, on a whim I changed this to:
<dtml-var "undb_dateout(dbdate=currentdatevar)">

And it worked...
Someone should add this to the DTML documentation, or at least make it stand
out more - it is VERY
useful... If no one else does I'll write-up a how-to on it.

>>>
>Message: 7
>Date: Thu, 25 Jan 2001 19:13:59 +0000 (GMT)
>From: Espen Sorbye Frederiksen <ceeesf@cee.hw.ac.uk>
>To: <zope-dev@zope.org>
>Subject: Message: 7
>Date: Thu, 25 Jan 2001 19:13:59 +0000 (GMT)
>From: Espen Sorbye Frederiksen <ceeesf@cee.hw.ac.uk>
>To: <zope-dev@zope.org>
>Subject: [Zope-dev] Passing arguments to DTML Methods
>
>Sorry this, possibly, very trivial question:
>
>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?
>
>Hope someone kindly could answer my question,
>
>Espen
>
>
>
>