I am just getting started in Zope and have what is probably an obvious question. I have an external method that returns a list. I understand how to write dtml to iterate through the list using <dtml-in>. My question is how do I write a dtml-method that takes the current sequence-item and does something in it. So in index_html <dtml-in "my_external_method()"> <dtml-var the_other_dtml_method(sequence-item)> </dtml-in> And in the other dtml-method, how do I access the sequence-item passed in? Thanks, -- Greg Green e-mail: gpgreen@olywa.net http://www.olywa.net/gpgreen/
On Fri, Apr 21, 2000 at 10:55:50PM -0700, gpgreen@olywa.net wrote:
I am just getting started in Zope and have what is probably an obvious question. I have an external method that returns a list. I understand how to write dtml to iterate through the list using <dtml-in>. My question is how do I write a dtml-method that takes the current sequence-item and does something in it.
So in index_html
<dtml-in "my_external_method()">
<dtml-var the_other_dtml_method(sequence-item)>
The syntax you want, if I've understoof the question, is (untested): <dtml-var "the_other_dtml_method(_['sequence-item'])"> You need to do it this way because the stuff inside the quotes is a python expression and hyphens are not permitted in Python variable names. So you use the magical _ namespace, which contains things like sequence-item as a key. Cheers, Malcolm -- Malcolm Tredinnick email: malcolm@commsecure.com.au CommSecure Pty Ltd
On Sat, Apr 22, 2000 at 04:04:58PM +1000, Malcolm Tredinnick wrote:
The syntax you want, if I've understoof the question, is (untested): <dtml-var "the_other_dtml_method(_['sequence-item'])">
You need to do it this way because the stuff inside the quotes is a python expression and hyphens are not permitted in Python variable names. So you use the magical _ namespace, which contains things like sequence-item as a key.
Very nice. Now how do I reference the variable in the_other_dtml_method? I assume it is in the other methods namespace, but what name does it have? -- Greg Green e-mail: gpgreen@olywa.net http://www.olywa.net/gpgreen/
On Fri, Apr 21, 2000 at 11:33:16PM -0700, gpgreen@olywa.net wrote:
On Sat, Apr 22, 2000 at 04:04:58PM +1000, Malcolm Tredinnick wrote:
The syntax you want, if I've understoof the question, is (untested): <dtml-var "the_other_dtml_method(_['sequence-item'])">
You need to do it this way because the stuff inside the quotes is a python expression and hyphens are not permitted in Python variable names. So you use the magical _ namespace, which contains things like sequence-item as a key.
Very nice. Now how do I reference the variable in the_other_dtml_method? I assume it is in the other methods namespace, but what name does it have?
Doh! Please pay no attention to me ... I completely misread your question :-( I read the bit inside quotes as "Python_external_method". Bad me! No cookie! Onto the real answer: My understanding is that the namespaces are inherited for dtml-methods, so if you replace my gibberish above with <dtml-var the_other_dtml_method> you should still be able to talk about sequence-item. In a recent Zope site I have been working on, I did a lot of things that were exactly like this. The only difference was that because, in my case, sequence-item was a tuple, I would have things like this: <dtml-with "my_method_that_returns_a_list_of_tuples()"> <dtml-let name="_['sequence-item'][0]" title="_['sequence-item'][1]"> <dtml-var display_data> </dtml-let> </dtml-with> In this example, display_data was a dtml-method that put the 'name' and 'title' things in a table and it just referred to them as <dtml-var name> and <dtml-var title>. So talking about <dtml-var sequence-item> should be the same. My sincere apologies for the entirely misleading answer earlier. Cheers, Malcolm -- Malcolm Tredinnick email: malcolm@commsecure.com.au CommSecure Pty Ltd
Awesome! That did the trick. I'm starting to like this. -- Greg Green e-mail: gpgreen@olywa.net http://www.olywa.net/gpgreen/
gpgreen@olywa.net wrote:
On Sat, Apr 22, 2000 at 04:04:58PM +1000, Malcolm Tredinnick wrote:
The syntax you want, if I've understoof the question, is (untested): <dtml-var "the_other_dtml_method(_['sequence-item'])">
You need to do it this way because the stuff inside the quotes is a python expression and hyphens are not permitted in Python variable names. So you use the magical _ namespace, which contains things like sequence-item as a key.
Very nice. Now how do I reference the variable in the_other_dtml_method? I assume it is in the other methods namespace, but what name does it have?
-- Greg Green e-mail: gpgreen@olywa.net http://www.olywa.net/gpgreen/
_______________________________________________ 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 )
It doesn't need a name. It will be the only variable available. Call it whatever you want. Declare the external method as 'def otherExternalMethod(self, my_var):', and the sequence-item is available in my_var, and you can access the current folder in self. You can always call the second method as <dtml-var "otherExtMethod(my_var=_['sequence-item'])"> (I think, untested). Just a note... loops in dtml are relly inefficient. If it is at all possible, pass the entire list into the second method, and iterate through the list in python. It will be MUCH faster. --sam
gpgreen@olywa.net wrote:
I am just getting started in Zope and have what is probably an obvious question. I have an external method that returns a list. I understand how to write dtml to iterate through the list using <dtml-in>. My question is how do I write a dtml-method that takes the current sequence-item and does something in it.
So in index_html
<dtml-in "my_external_method()">
<dtml-var the_other_dtml_method(sequence-item)>
</dtml-in>
And in the other dtml-method, how do I access the sequence-item passed in?
I like using: <dtml-var the_other_dtml_method( nameOfVariable=sequence-item )> then somewhere in the_other_dtml_method you refer to the variable by its name: nameOfVariable. ------------------------------------------------------ Andres Corrada-Emmanuel Email: andres@corrada.com ------------------------------------------------------
participants (4)
-
Andres Corrada -
gpgreen@olywa.net -
Malcolm Tredinnick -
Sam Gendler