[PEAK] Templates with layout

Radek Kanovsky rk at dat.cz
Mon Jun 6 10:45:43 EDT 2005

Lets have some simple PWT template "repr.pwt":

        <html this:is="page">
            <div content:replace="."/>

It correctly shows repr() of the underlying object. Everything is OK untill 
we try to use some layout:


        <html with:page-layout="@@layout">
            <div this:is='body' content:replace="."/>


        <html this:is="page">
            <div this:replace="/params/body"/>
Then we end in infinite recursion, because current object in repr.pwt
is not underlying object but parsed layout.pwt template. Workaround
is to use ``content:replace=".."'' in repr.pwt but I am almost sure
that this is not intended behaviour. Following patch solve the problem
but may have some undesired side effects that I am not aware of now.

Index: templates.py
--- templates.py	(revision 53)
+++ templates.py	(working copy)
@@ -626,7 +626,9 @@
             elif path=='/default':
                 return super(TemplateDocument,self)
-                return Replace(self, dataSpec=path, params=self.params.copy())
+                wrap = LayoutParamWrapper
+                params = dict([(p,wrap(v)) for p,v in self.params.iteritems()])
+                return Replace(self, dataSpec=path, params=params)
         if attrName in self.params:
             return IDOMletRenderable(self.params[attrName])
@@ -638,9 +640,15 @@
     fragment = page = binding.Make(layoutDOMlet)
+class LayoutParamWrapper(object):
+    protocols.advise(instancesProvide=[IDOMletRenderable])
+    def __init__(self, elem):
+        self.elem = elem
+    def renderFor(self, ctx, state):
+        return self.elem.renderFor(ctx.previous, state)


More information about the PEAK mailing list