[ZPT] Generating Page Templates ..

Jean Jordaan jean@upfrontsystems.co.za
Tue, 11 Mar 2003 09:43:32 +0200


Hi Chris

 > It's this code I'm interested in seeing 'cos it's where the
 > problem lies...

We've dropped the view method. Now, we're parsing the template and
inserting the resulting tree in the DOM that we're building
(appendChild, below). Before, we didn't first call and parse the
template (a ZPT): we inserted a reference to it, like
"<span tal:replace='structure here/referenced_template' />", for
Zope to render (and we couldn't figure out how to make Zope do the
rendering).

In the following, qti_object is an object representing a node in a
http://www.imsglobal.org/question/ questionnaire, and we're building an
XHTML document from a tree of these nodes. ::

     def _process(self, qti_object, parent):
         mt = qti_object.meta_type
         element = None

         [...]
         elif mt == 'MaterialText':
             if qti_object.uri:
                 path = '%s/%s' % ('/'.join(qti_object.getPhysicalPath()),
                     qti_object.uri)
                 template = qti_object.restrictedTraverse(path)
                 template = '<div class="included">%s</div>' % template()
                 tdom = parseString(template)
                 parent.appendChild(tdom.childNodes[0])
                 element = None
         [...]

         if zqti.QTIContainer in qti_object.__class__.__bases__:
             for ob in qti_object.objectValues():
                 self._process(ob, element)

This used to be::

             if qti_object.uri:
		element = self.createElement('span')
		element.setAttribute('tal:replace',
			'structure container/%s' % qti_object.uri)

-- 
Jean Jordaan
http://www.upfrontsystems.co.za