[ZPT] trying to understand ZPT macros...

Clemens Robbenhaar zpt@zope.org
Wed, 8 Jan 2003 15:58:29 +0100


Hi Anthony,

 [...]
 > >  <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.
 > 

 er, yes, I should have read the code more closely. :(

 There is a 'macros' variable used in Your page template. Where does
this come from? 

 > 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()

 If I read this right, there is no "macros" variable in the context yet.
Is this moved from the 'self.macros' variable in the page template
somehow? 

 It seems _me_ is the one missing something here ;-).
 You may have a custom TALESEngine which does mix in something in
the context I cannot see here.

Cheers,
Clemens


BTW, defining and using a marco in the same page template indded does
not work within Zope at least, see

 http://lists.zope.org/pipermail/zpt/2002-September/003756.html

 > 
 > 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.
 > 
 > 
 > _______________________________________________
 > ZPT mailing list
 > ZPT@zope.org
 > http://lists.zope.org/mailman/listinfo/zpt