[Zope] ZPT tal:define scoping with METAL

Ed Leafe ed at leafe.com
Thu Sep 4 16:57:14 EDT 2003


	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.

	I'm guessing that the full page isn't being evaluated as it appears, 
but rather each of the slots is evaluated separately. Is that correct? 
If so, is there an alternative to having to define the "results" twice 
(once for each slot)?


      ___/
     /
    __/
   /
  ____/
  Ed Leafe
  http://leafe.com/
  http://opentech.leafe.com




More information about the Zope mailing list