return type of methods for use in "in" tag
a quick one: what type of object does an external method have to return that I want to call in an "in" tag? I want to iterate over a list if items that has two properties: url and text example <dtml-in "mymethod"> <dtml-var url> <dtml-var text> </dtml-in> best regards H. -- Heiko Stoermer MIG Augsburg
On Sun, 5 Sep 1999, Heiko Stoermer wrote:
a quick one: what type of object does an external method have to return that I want to call in an "in" tag?
One option (and they are many) is to return a list of instances. Then if you iterate over the list using <dtml-in ...> the attributes of those instances will be made available in the namespace. for example (untested) class Helper: pass def mymethod(self): out=[] for i in range(10): tmp=Helper() tmp.no=i tmp.name='spam' out.append(tmp) return out and call it like:
<dtml-in "mymethod"> <dtml-var no> <dtml-var name> </dtml-in>
Pavlos
Pavlos Christoforou wrote:
On Sun, 5 Sep 1999, Heiko Stoermer wrote:
a quick one: what type of object does an external method have to return that I want to call in an "in" tag?
One option (and they are many) is to return a list of instances. Then if you iterate over the list using <dtml-in ...> the attributes of those instances will be made available in the namespace.
for example (untested)
class Helper: pass
def mymethod(self): out=[] for i in range(10): tmp=Helper() tmp.no=i tmp.name='spam' out.append(tmp) return out
and call it like:
<dtml-in "mymethod"> <dtml-var no> <dtml-var name> </dtml-in>
Pavlos
this worked right out of the box! (I was a little astonished that you can acces properties a class does not have, but o.k., that's python I guess.) thanks a lot. Heiko -- Heiko Stoermer MIG Augsburg
participants (2)
-
Heiko Stoermer -
Pavlos Christoforou