What kind of result do I need to return from a python method in order for the return value to be usable by <dtml-in> ? In other words, I want to do: def blah(self): l = [{val : 'blah1'}] return l then in my dtml code do: <dtml-in blah> <dtml-var val1> </dtml-in> Am I missing something? -- You will be reincarnated as a toad; and you will be much happier.
jiva@devware.com wrote:
What kind of result do I need to return from a python method in order for the return value to be usable by <dtml-in> ?
A sequence.
In other words, I want to do:
def blah(self): l = [{val : 'blah1'}] return l
then in my dtml code do:
<dtml-in blah> <dtml-var val1> </dtml-in>
Am I missing something?
You are iterating over a list that contains one item. The in block will be execute once at which time the dictionary which is the only item in the list will be pushed on the DTML namespace stack. You then ask for the name 'val1', which does not exist in any namespace, even the namespace of the dictionary. It is a *key* in the dictionary, but it is not a name of the dictionary. <dtml-in blah> <dtml-var "_['sequence-item'][val1]"> </dtml-in> Well use the val1 key to get the value 'blah1' out of the dictionary (which is sequence-item). -Michel
Okay, actually, that was a typo, it should have been <dtml-var val> Does that change anything or no? On Tue, Mar 28, 2000 at 11:57:44AM -0800, Michel Pelletier wrote:
jiva@devware.com wrote:
What kind of result do I need to return from a python method in order for the return value to be usable by <dtml-in> ?
A sequence.
In other words, I want to do:
def blah(self): l = [{val : 'blah1'}] return l
then in my dtml code do:
<dtml-in blah> <dtml-var val1> </dtml-in>
Am I missing something?
You are iterating over a list that contains one item. The in block will be execute once at which time the dictionary which is the only item in the list will be pushed on the DTML namespace stack. You then ask for the name 'val1', which does not exist in any namespace, even the namespace of the dictionary. It is a *key* in the dictionary, but it is not a name of the dictionary.
<dtml-in blah> <dtml-var "_['sequence-item'][val1]"> </dtml-in>
Well use the val1 key to get the value 'blah1' out of the dictionary (which is sequence-item).
-Michel
-- Cinemuck, n.: The combination of popcorn, soda, and melted chocolate which covers the floors of movie theaters. -- Rich Hall, "Sniglets"
What kind of result do I need to return from a python method in order for the return value to be usable by <dtml-in> ?
In other words, I want to do:
def blah(self): l = [{val : 'blah1'}] return l
Here's one way to do it. There may be others: <dtml-in blah mapping> <dtml-var _['sequence-item']['val']> </dtml-in> The 'mapping' parameter to dtml-in causes it to treat the sequence items as mappings instead of instances. Then "_['sequence-item']" refers to the dictionary object and "_['sequence-item']['val']" refers to the 'val' element of that dictionary. -jfarr
participants (3)
-
jiva@devware.com -
Jonothan Farr -
Michel Pelletier