[Zope-dev] pseudo database records for the "in" tag?
Jeffrey P Shell
jeffrey@Digicool.com
Tue, 09 Mar 1999 10:15:13 -0500
> From: julian@zereau.net I need to know how to structure dynamic tabular data
> (returned from an external method) so that the "in" tag can handle it like it
> does the results of a SQL method and do automatic variable setting etc.
Just return a sequence of mapping objects (dictionaries) or instances. One
thing to note when looping over a sequence of mapping objects with the in
tag, the parameter "mapping" must be set. For example, with the external
method::
def emQuickTest(self):
r=[]
nl={'name': 'bob',
'job' : 'slob',}
r.append(nl)
nl={'name': 'jill',
'job' : 'pill',}
r.append(nl)
return r
With an external method object named emQuickTest, use the following DTML:
<!--#in emQuickTest mapping-->
<P><STRONG>name:</STRONG> <!--#var name--><BR>
<STRONG>job:</STRONG> <!--#var job--></P>
<!--#/in-->
("mapping" tells the #in tag to do a 'getitem' instead of 'getattr' to get
the names. 'getitem' works with dictionary/dictionary-like objects.
'getattr' works with instances.)
This will result in returned HTML like the following
<P><STRONG>name:</STRONG> bob<BR>
<STRONG>job:</STRONG> slob</P>
<P><STRONG>name:</STRONG> jill<BR>
<STRONG>job:</STRONG> pill</P>
.jPS | jeffrey@digicool.com
zope, through the web. www.zope.org