[Zope] ZPT tal:define scoping with METAL

Dieter Maurer dieter at handshake.de
Fri Sep 5 22:00:15 EDT 2003


Ed Leafe wrote at 2003-9-4 15:57 -0400:
 > 	I have a ZPT page where I need to create two sections that both 
 > iterate off of the same query. The query can be long, so I'd strongly 
 > prefer to run it once. No problem, I thought - just define it in an 
 > outer
 > <div> tag - I've done that on lots of other pages.
 > 
 > 	However, on this page, each of the two "inner" sections are defined as 
 > fill-slots for an overall template. Here's a rough idea of the 
 > structure:
 > 
 > <html metal:use-macro="myTemplate">
 > <body>
 > 
 > <!-- This is the very slow query -->
 > <div tal:define="results here/someQuery">
 > 
 > 	<div metal:fill-slot="leftside">
 > 		<table>
 > 			<tr tal:repeat="res results">
 > 				...
 > 			</tr>
 > 		</table>
 > 	</div>
 > 
 > 	<div metal:fill-slot="rightside">
 > 		<table>
 > 			<tr tal:repeat="res results">
 > 				...
 > 			</tr>
 > 		</table>
 > 	</div>
 > 
 > </div>
 > </body>
 > </html>
 > 
 > 	When this page is displayed, however, I get an error that "results" is 
 > not defined, and it points to the line with the first tal:repeat 
 > statement. I tried adding the 'global' keyword to the tal:define, but 
 > it made no difference.
 
If your "div ... results here/someQuere" is executed (and e.g. not replaced
by the macro body), then this will work.
There is a common namespace shared by template and macro.


Note however, that the complete

     <XXXX metal:use-macro="...">
       ...
     </XXXX>

is replaced by the macro body (with just the fill-slot inserted).


Dieter



More information about the Zope mailing list