[Zope] Page Templates are great, but...

Chris Withers chrisw@nipltd.com
Sun, 02 Jun 2002 09:24:00 +0100


Stuart Bishop wrote:
> 
> <html metal:use-macro="here/standard_template.pt/macros/page>
> <body>
> <div tal:replace="python: here.banner_ad('car_ad')">Banner Ad</div>
> <div metal:fill-slot="body">
> My content
> </div>
> </body>
> </html>

Al little bit neater and more correct:

<html metal:use-macro="here/standard_template.pt/macros/page>
<body metal:fill-slot="body">
<tal:r replace="python: here.banner_ad('car_ad')"/>

My content

</body>
</html>

> > 2.) Symbols
> > How am I supposed to work with symbolic information like
> > table width? Of course, I'm free to create python-functions
> > which pull the raw figures from a config-file or db, but
> > having a separate function for each of the dozens of symbols
> > I would need will give me carpal tunnel syndrome.

I know what you mean ;-)

There's two approaches depending on how complex things are.

If they're quite simple, you can just use inline paths and python:

<table tal:attributes="border here/border_width">
<tr>
<td width="10%">
</td>
<td tal:attributes="width python:str(here.page_width-10)+'%'">
</td>
</tr>
</table>

if they're complex, then you can have a python script which returns a
dictionary:

dict={}
# information from context
total_width = float(context.total_width)
current = float(context.current_value)
target  = float(context.target_value)
# width calculation
red = (current/target)*total_width

Netscape doesn't like images with a width of 0
if red==0:
  red=1
elif red==total_width:
  red-=1

# store retults
dict['red'] = red
dict['white'] = total_width - red

return dict

...and use that in the ZPT:

<td tal:define="widths here/calculateWidths"><img
  src="red.gif" height="10" 
  tal:attributes="width widths/red"><img
  src="white.gif" height="10" 
  tal:attributes="width widths/white"></td>

cheers,

Chris