I've got situation where I want a dtml-method to return a list of tuple objects. I then want to iterate over the tuples using a dtml-in construct, displaying the various parts of the tuple. For example, suppose I want to return a list of URL tags and names like this: <dtml-return "[('Go Here', 'foo.bar.com') , ('Go Somewhere Else', 'baz.foo.com')]"> I would like to do something like this with this result: <dtml-in urltags> <a href="< url part from tuple >">< display part of tuple ></a> </dtml-in> Is there a way to do this and if so, what is the magical syntax to make this happen? I'm also interested in knowing how I might use a collection of mapping objects in a similar manner. Thanks! James W. Howe mailto:jwh@allencreek.com Allen Creek Software, Inc. pgpkey: http://ic.net/~jwh/pgpkey.html Ann Arbor, MI 48103
----- Original Message ----- From: "James W. Howe" <jwh@allencreek.com> To: <zope@zope.org> Sent: Monday, February 28, 2000 1:07 PM Subject: [Zope] Returning lists of tuples
I've got situation where I want a dtml-method to return a list of tuple objects. I then want to iterate over the tuples using a dtml-in construct, displaying the various parts of the tuple. For example, suppose I want to return a list of URL tags and names like this:
<dtml-return "[('Go Here', 'foo.bar.com') , ('Go Somewhere Else', 'baz.foo.com')]">
I would like to do something like this with this result:
<dtml-in urltags> <a href="< url part from tuple >">< display part of tuple ></a> </dtml-in>
Is there a way to do this and if so, what is the magical syntax to make this happen? I'm also interested in knowing how I might use a collection of mapping objects in a similar manner.
(untested): <dtml-in urltags> <a href="<dtml-var "_['sequence-item'][1]">"><dtml-var "_['sequence-item'][0]"></a> </dtml-in> The syntax is somewhat verbose, but should do the trick just fine. Kevin
At 01:50 PM 2/28/00 -0500, Kevin Dangoor wrote:
----- Original Message ----- From: "James W. Howe" <jwh@allencreek.com> To: <zope@zope.org> Sent: Monday, February 28, 2000 1:07 PM Subject: [Zope] Returning lists of tuples
I've got situation where I want a dtml-method to return a list of tuple objects. I then want to iterate over the tuples using a dtml-in construct, displaying the various parts of the tuple. [...]
(untested):
<dtml-in urltags> <a href="<dtml-var "_['sequence-item'][1]">"><dtml-var "_['sequence-item'][0]"></a> </dtml-in>
The syntax is somewhat verbose, but should do the trick just fine.
Before I received your message, I tried the following (which also seems to work): <dtml-in urltags> <a href="<dtml-var sequence-item>"><dtml-var sequence-key></a> </dtml-in> I'm not entirely sure why this works. Your code makes more sense (although it is more verbose) James W. Howe mailto:jwh@allencreek.com Allen Creek Software, Inc. pgpkey: http://ic.net/~jwh/pgpkey.html Ann Arbor, MI 48103
----- Original Message ----- From: James W. Howe <jwh@allencreek.com>
<dtml-return "[('Go Here', 'foo.bar.com') , ('Go Somewhere Else', 'baz.foo.com')]">
I would like to do something like this with this result:
<dtml-in urltags> <a href="< url part from tuple >">< display part of tuple ></a> </dtml-in>
dtml-in has a special case for lists of two-tuples like this. It makes the first element of each tuple 'sequence-key' and the second 'sequence-item'. Try... <a href="&dtml-sequence-item;">&dtml-sequence-key;</a> Cheers, Evan @ 4-am & digicool
At 01:25 PM 2/28/00 -0600, Evan Simpson wrote:
----- Original Message ----- From: James W. Howe <jwh@allencreek.com>
<dtml-return "[('Go Here', 'foo.bar.com') , ('Go Somewhere Else', 'baz.foo.com')]">
I would like to do something like this with this result:
<dtml-in urltags> <a href="< url part from tuple >">< display part of tuple ></a> </dtml-in>
dtml-in has a special case for lists of two-tuples like this. It makes the first element of each tuple 'sequence-key' and the second 'sequence-item'. Try...
<a href="&dtml-sequence-item;">&dtml-sequence-key;</a>
I tried that very thing and was surprised that it worked. The reason I was surprised was because I would have expected sequence-item to have answered the tuple object itself, rather than just the "value" component. It would seem that sequence-item should always answer the item itself, and there should be two special variables, sequence-key and sequence-value which answer the key and value respectively if the sequence-item happens to be a tuple or mapping. Anyway, thanks for the info. James W. Howe mailto:jwh@allencreek.com Allen Creek Software, Inc. pgpkey: http://ic.net/~jwh/pgpkey.html Ann Arbor, MI 48103
participants (3)
-
Evan Simpson -
James W. Howe -
Kevin Dangoor