[Zope-dev] What to return to a document and how to access it

Thomas Weholt Thomas@cintra.no
Fri, 19 May 2000 11:06:30 +0200


Hi,

These are defined in a product:

#-----------------------------------------------------------------------

class SomeClass:
	"""DocString"""

	def __init__(self):
		"""DocString""""
		pass

SomeDoc = HTMLFile('Some', globals()) #  Some.dtml -> DTML-document

def SomeMethod(self, values = '', REQUEST): # the values put into the method
isn`t important now
	"""Docstring"""

	a = SomeClass()
	a.values = {}
	a.values['1'] = [1,2,3,4,5]
	a.values['2'] = [323,3,4,41,25]
	a.plain_string = 'test'
	a.list = [32,435,21,9]
	
	return self.SomeDoc(self, a)

#-----------------------------------------------------------------------

How can I access the returned object in 'Some.dtml'?
I`ve tried stuff like:

1: ( I want the plain_string-property of the a-object )

	<dtml-var a.plain_string>

2: ( the same )
	<dtml-in a>
		<dtml-var plain_string>
	</dtml-in>

3: ( the same )

	<dtml-in a>
		<dtml-var a.plain_string>
	</dtml-in>

4. 
	<dtml-in a>
		<dtml-var a.values['1']>
	</dtml-in>

I get a NameError and KeyError etc. It works if I return a dictionary with
keys pointing to single values, but I want to return a whole object, and do
stuff like :

#-----------------------------------------------------------------------

	<dtml-with a>
		<h2><dtml-var plain_string></h2>
		<dtml-in a.values>
			<li><dtml-var ???><!-- extract keys in
a.values-dictionary --->
			<ul>
			<dtml-in ???>
				<dtml-var ???><!-- create pretty listing of
the items in the list the key points to --->
			</dtml-in>
			</ul>
		</dtml-in>
		<ul>
		<dtml-in a.list>
			<li><dtml-var ???><!--- list items in the list in
a.list--->
		</dtml-in>
		</ul>
	</dtml-with>
	
#-----------------------------------------------------------------------

What I want in HTML :

	<h2>test</h2>
		<li>1
		<ul>
			<li>1
			<li>2
			<li>3
			<li>4
			<li>5
		</ul>
		<li>2
		<ul>
			<li>323
			<li>3
			<li>4
			<li>41
			<li>25
		</ul>
		<ul>
			<li>32
			<li>435
			<li>21
			<li>9
		</ul>

If somebody could show me how to access the stuff returned in the method
above, I`d be grateful.


Thomas