Re: [Zope-dev] Passing arguments to DTML Methods

2001-01-26 Thread Jon Franz

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 + (GMT)
From: Espen Sorbye Frederiksen [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Subject: Message: 7
Date: Thu, 25 Jan 2001 19:13:59 + (GMT)
From: Espen Sorbye Frederiksen [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
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





___
Zope-Dev maillist  -  [EMAIL PROTECTED]
http://lists.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML encoding!  **
(Related lists - 
 http://lists.zope.org/mailman/listinfo/zope-announce
 http://lists.zope.org/mailman/listinfo/zope )




[Zope-dev] Passing arguments to DTML Methods

2001-01-25 Thread Espen Sorbye Frederiksen

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


___
Zope-Dev maillist  -  [EMAIL PROTECTED]
http://lists.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML encoding!  **
(Related lists - 
 http://lists.zope.org/mailman/listinfo/zope-announce
 http://lists.zope.org/mailman/listinfo/zope )




Re: [Zope-dev] Passing arguments to DTML Methods

2001-01-25 Thread Dieter Maurer

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

___
Zope-Dev maillist  -  [EMAIL PROTECTED]
http://lists.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML encoding!  **
(Related lists - 
 http://lists.zope.org/mailman/listinfo/zope-announce
 http://lists.zope.org/mailman/listinfo/zope )




Re: [Zope-dev] Passing arguments to DTML Methods

2001-01-25 Thread Espen Sorbye Frederiksen

Thank you Dieter!

Espen

On Thu, 25 Jan 2001, Dieter Maurer wrote:

 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



___
Zope-Dev maillist  -  [EMAIL PROTECTED]
http://lists.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML encoding!  **
(Related lists - 
 http://lists.zope.org/mailman/listinfo/zope-announce
 http://lists.zope.org/mailman/listinfo/zope )