Re: [Zope] How to Pass values to a DTML method ??
Stuart Foster writes:
I have a DTML method that is called from a document. I need to pass a value to it like a parameter would be passed to a function.
<dtml-var some_method(param=value)> That does not look too bad, but you forgot the "..." around the call.
You should include two positional parameters as well: <dtml-var "some_method(_.None,_,param=value)"> Otherwise, you cut the namespace propagation. Dieter
This is the way I had to do it what's up with the two extra params? -----Original Message----- From: zope-admin@zope.org [mailto:zope-admin@zope.org]On Behalf Of Dieter Maurer Sent: Monday, September 11, 2000 2:24 PM To: Stuart Foster Cc: Zope List Subject: Re: [Zope] How to Pass values to a DTML method ?? Stuart Foster writes:
I have a DTML method that is called from a document. I need to pass a value to it like a parameter would be passed to a function.
<dtml-var some_method(param=value)> That does not look too bad, but you forgot the "..." around the call.
You should include two positional parameters as well: <dtml-var "some_method(_.None,_,param=value)"> Otherwise, you cut the namespace propagation. Dieter _______________________________________________ Zope maillist - Zope@zope.org http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
Dieter Maurer You should include two positional parameters as well:
<dtml-var "some_method(_.None,_,param=value)">
I've recently had explained to me a way that is more robust, and possibly less confusing, than this idiotic idiom. I think it may start appearing in docs and training. <dtml-let param="value"><dtml-var some_method></dtml-let> ...or even better... <dtml-let param="value">&dtml.-some_method;</dtml-let> ...which allows nicely for stuff like: <dtml-let foo="sequence-item" bar="foo.objectIds()" firstbar="bar[0]"> <a href="&dtml-firstbar;">First!</a> </dtml-let> Cheers, Evan @ digicool & 4-am
The first example is what I was doing. But felt it was hard to follow. However I would be interested in why it would be considered more robust. -----Original Message----- From: Evan Simpson [mailto:evan@4-am.com] Sent: Monday, September 11, 2000 8:15 PM To: Stuart Foster; Dieter Maurer Cc: Zope List Subject: Re: [Zope] How to Pass values to a DTML method ??
Dieter Maurer You should include two positional parameters as well:
<dtml-var "some_method(_.None,_,param=value)">
I've recently had explained to me a way that is more robust, and possibly less confusing, than this idiotic idiom. I think it may start appearing in docs and training. <dtml-let param="value"><dtml-var some_method></dtml-let> ...or even better... <dtml-let param="value">&dtml.-some_method;</dtml-let> ...which allows nicely for stuff like: <dtml-let foo="sequence-item" bar="foo.objectIds()" firstbar="bar[0]"> <a href="&dtml-firstbar;">First!</a> </dtml-let> Cheers, Evan @ digicool & 4-am
From: Stuart Foster <stuartafoster@home.com>
The first example is what I was doing. But felt it was hard to follow. However I would be interested in why it would be considered more robust.
I probably misused the word; what I meant was that the <dtml-let> form is less likely to have errors like forgetting the first two "magic" parameters or writing "sequence-item" instead of "_['sequence-item']", and can take advantage of current <dtml-let> features such as cascading assignment (foo=1, bar=foo+1, etc) and future ones such as extended-attribute syntax (foo-name-name="x" instead of foo="_[_[x]]"). I have considered proposing that we graft <dtml-let>'s capabilities onto the other tags, so that we could write stuff like: <dtml-var set-foo="getFoo()" var=foo set-param1=" 'text' " set-param2="id"> ...or... <dtml-in in="seq" set-seqKey=sequence-key set-letter="seqKey[0]"> &dtml-letter; </dtml-in> Cheers, Evan @ digicool & 4-am
They pass in the current name space, the context if you will. Someone posted a reply that had a link to the faq that attempts to explains this. DR Stuart Foster wrote:
This is the way I had to do it what's up with the two extra params?
-----Original Message----- From: zope-admin@zope.org [mailto:zope-admin@zope.org]On Behalf Of Dieter Maurer Sent: Monday, September 11, 2000 2:24 PM To: Stuart Foster Cc: Zope List Subject: Re: [Zope] How to Pass values to a DTML method ??
Stuart Foster writes:
I have a DTML method that is called from a document. I need to pass a value to it like a parameter would be passed to a function.
<dtml-var some_method(param=value)> That does not look too bad, but you forgot the "..." around the call.
You should include two positional parameters as well:
<dtml-var "some_method(_.None,_,param=value)">
Otherwise, you cut the namespace propagation.
Dieter
_______________________________________________ Zope maillist - Zope@zope.org http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
_______________________________________________ Zope maillist - Zope@zope.org http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
Stuart Foster writes:
Dieter Maurer wrote:
You should include two positional parameters as well:
<dtml-var "some_method(_.None,_,param=value)"> This is the way I had to do it what's up with the two extra params? DTML objects use the DocumentTemplate's (--> DocumentTemplate.DT_String) __call__ function for rendering.
This function has two (optional) positional arguments, "client" and "mapping" and an arbibrary number of keyword parameters. All these parameters together determine the content of this magic "namespace" that is used for name resolution inside the DocumentTemplate. If you want more details about this, look either at the source code documentation or search the lists archive for another post where I explained that in more detail. For a DTML object "name", <dtml-var name> is equivalent to <dtml-var "name(_.None,_)">, i.e. the client is "None" and the mapping is the namespace object "_". This propagates the namespace of the calling object into the called DTML object. If you use <dtml-var "name(kp1=v1, kp2=v2, ...)">, i.e. you do not provide parameters for the positional parameters, there use their default value, "None". This implies that the outer namespace and the corresponding context is not available in the called DocumentTemplate. Dieter
participants (4)
-
Daniel Rusch -
Dieter Maurer -
Evan Simpson -
Stuart Foster