[Zope-dev] FW: Re: [Zope-dev] Passing arguments to DTML Methods
PS: my example assumes you _only_ want passed arguments to be usable to the DTML method you are calling - if you want to pass parameters And get the default namespace, you have to pass it ('_') also. My util methods that use params Only use those params (I try to keep a clean interface) - but yours might not... >-Original Message- >From: Jon Franz >Sent: Friday, January 26, 2001 2:07 PM >To: '[EMAIL PROTECTED]' >Cc: '[EMAIL PROTECTED]' >Subject: Re: [Zope-dev] Passing arguments to DTML Methods > > >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: > > > >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: > > > > >Then, on a whim I changed this to: > > >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: [Zope-dev] Passing arguments to DTML Methods <> >>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
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: 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: Then, on a whim I changed this to: 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 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
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 > 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: > > > > 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: > > param2="value2" > > > > > > 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
Espen Sorbye Frederiksen writes: > How do you pass on variables to a DTML Method. > If I would use a python method I would use 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: 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: 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 )
[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 . 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 )