[Zope] dtml-in format

Ben Bush ben at center7.com
Thu Aug 7 17:24:06 EDT 2003


I would like to use dtml-in to iterate through some results in a python 
script. I am not sure what format I need to put the results into in my 
python script to be able to reference them in the <dtml-in> tags. I am 
currently trying to return a dictionary but that does not seem to work.

Here is how I have it setup.

I have a DTML-method with a DTML-IN block that trys to printout the 
<dtml-var name> variable.

<dtml-in currentItems>
   <dtml-var name>
</dtml-in>

The object currentItems is a python script. Here is a copy of it. I 
print out the return results and it goes back as a list with a 
dictionary per item.

## Script (Python) "current_items"
##bind container=container
##bind context=context
##bind namespace=
##bind script=script
##bind subpath=traverse_subpath
##parameters=
##title=
##
# Get a list of the current items in the cart and return it back in a 
table format

# Provide access to session data
session=context.REQUEST.SESSION

# Only get items if the cart has been established
if session.has_key('cart'):
   cart=session.get('cart', {})
   cart_items=[]
   # Lets loop through our cart and get each item
   for product_id, quantity in cart.items():
     item=context.get_item(product_id=product_id).dictionaries()
     for record in item:
       record['quantity']=quantity
       #print record, "<br>"
       cart_items.append(record)
   print cart_items
   return printed
   #return cart_items
else:
   # No Cart established, no need to return anything
   return

Any help would be greatly appreciated.

Thanks,

-- 
Ben Bush
Center 7, Systems Administrator
801-655-2640




More information about the Zope mailing list