[ZPT] trying to understand ZPT macros...

Anthony Baxter Anthony Baxter <anthony@interlink.com.au>
Thu, 09 Jan 2003 01:02:32 +1100


>>> Clemens Robbenhaar wrote
>  This happens because the 'metal:use-macro' eats the complete tag,
> including the 'tal:define', which is not executed at all.

I thought that might be the case, but when I tried the expanded version,
it still failed.

> You need to do double nesting like:
> 
>  <tal:params define="linkgroup python:blog.linkGroups.get('blogs')">
>     <metal:block use-macro="macros/renderLinkGroup" />
>  </tal:params>

Hm. Well, I tried this exact same thing, and it's still not happy.

Here's some more info - I'm using ZPT outside zope, and it's all been
happy (until now :)

Here's a (heavily trimmed) bit of code:

class BlogTemplate(PageTemplate.PageTemplate):
    def render(self, blog, page):
        c = { 'blog': blog, 'page': page }
        output = StringIO.StringIO()
        TALInterpreter(self._v_program, self.macros,
            getEngine().getContext(c), output, tal=1, strictinsert=0)()
        return output.getvalue()

def go(blogObj):
    templ = BlogTemplate()
    templ.pt_edit(open('page.zpt'), 'text/html')
    print pt.render(blogObj)  

Examining the 'macros' attribute seems to show that the macro has been
loaded up and parsed. It just seems like I'm missing something obvious... :-/


-- 
Anthony Baxter     <anthony@interlink.com.au>   
It's never too late to have a happy childhood.