[ZPT] strange metal error

Joel Burton joel@joelburton.com
Thu, 21 Feb 2002 00:02:57 -0500 (EST)


On Wed, 20 Feb 2002, Brad Clements wrote:

> Here's a weird situation, can anyone explain?
>
> Two Page Templates, Master, which looks like this:
>
> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
> "http://www.w3.org/TR/REC-html40/loose.dtd">
> <html metal:define-macro="Master">
>   <head>
>     <link rel="stylesheet" type="text/css"
>         tal:attributes="href python:here.StyleSheet.absolute_url()" />
>     <title tal:content="template/title">The title</title>
>   </head>
>   <body tal:define="bgcolor template/bgcolor|string:white" tal:attributes="bgcolor
> bgcolor">
>   <span tal:omit-tag="" tal:replace="structure here/JavaScript" />
>
> .. more snipped out ..
>
>
> Then, index_html, which looks like this:
>
> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 3.2//EN">
> <html>
>   <head>
>     <title tal:content="template/title">The title</title>
>   </head>
>
>   <body>
>     <div metal:use-macro="here/Master/macros/Master">
>       <div metal:fill-slot="main">
>
> ..  stuff here snipped out ..
>
>
> When I Test index_html, and view the source, I get this:
>
> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 3.2//EN">
> <html>
>   <head>
>     <title></title>
>   </head>
>
>   <body>
>     <html>
>   <head>
>     <link rel="stylesheet" type="text/css"
>           href="http://marimba.murkworks.com:6180/Holmes/StyleSheet" />
>     <title></title>
>   </head>
>   <body bgcolor="#990033">
>   <SCRIPT LANGUAGE="JavaScript">
>
>
> Notice TWO <body> tags!
>
> (I also see the DOCTYPE is different but that's okay)
>
> Index_html has de-selected "expand macros when editing"

You're defining the macro as being the entire template (define-macro is on
the HTML tag); you're expanding the macro on the index_html BODY tag.

You probably want something like this:


template:

<html metal:define-macro="page">
 ...
  <body metal:define-slot="body">
  ... will normally be overridden by the real page ...
  </body>
</html>


index_html:

<html metal:use-macro="/path/to/template/macros/page">
  ... doesn't matter what goes here, will really come from template ...
  <body metal:fill-slot="body">
  ...
  </body>
</html>


This will let your index_html pick up the entire HEAD section, but let you
redefine the BODY section.

examples.zexp in Zope 2.5 have excellent examples of ZPT templates.

HTH.


-- 

Joel BURTON  |  joel@joelburton.com  |  joelburton.com  |  aim: wjoelburton
Independent Knowledge Management Consultant