[Zope] zpt, metal and missing content objects (bit long)

Tim Hicks tim@sitefusion.co.uk
Thu, 12 Sep 2002 14:20:20 +0100


zpt users,

I don't have much experience with zpts, but my experiments this morning
aren't really throwing up good things so far.  My main problems seem to stem
from METAL, which I want to use to mimic the behaviour <dtml-var
standard_html_header/footer>.

So, I have a zpt called 'standard_template' in my root folder.  It defines a
whole page macro called 'page' which in turn has a slot defined within it
called 'body'.

Next, I setup a zpt somewhere else to store content, that acquires the
'standard_template' zpt and uses it in the following way:

<html metal:use-macro="container/standard_template/macros/page">
<head>
<title tal:content="here/title">Title Inserted</title>
</head>
<body>
<div metal:fill-slot="body">
<p>This is the real content of this content object.  I've had to go through
a lot to get it here!  All I really want in this object is this one
paragraph, not all the zpt shenanigans.</p>
</div>
</body>
</html>

Ok, so this works out fine.  But...

... what if I want to make some global changes to my site?  What if I want
to add a heading (on every page) right after my <body> tag, and I want it to
be the title of the zpt (not 'standard_template', but that using it).  Doing
the following doesn't seem to work when put in 'standard_template' as 'here'
is not what I want when being accessed within a macro.

<body>
<h1 tal:content="here/title">title inserted here</h1>

It seems to me, that the only way I could achieve this would be to put that
text into every individual zpt holding content.  I can't believe this is
right, so what am I missing?

It strikes me that what I really want is a simple object that when rendered,
has 'standard_template' called as a method of it.  In this case, I'd only
need to store the real content in the object, without all the zpt markup.  I
also wouldn't need METAL, macros, slots etc.  I'd just use TAL to insert
things into my 'standard_template' (perhaps based on properties of the
content object).  Even better, I would then have one (and only one) place
where the site layout is defined, so I could make global changes very
easily.

I've hacked together an example of just such a content object, but it's
hardly production ready, and I'm also constrained to use only those objects
packaged as part of the base zope installation (2.5.1 in this case).  At the
back of my mind, I can't help thinking that I must have the wrong end of the
stick.  Most people seem very positive about zpt and apparently use it very
successfully.  It seems to me that the product is missing one final object
that would actually make it work perfectly.

Hoping-for-enlightenment-ly yours,

tim (of the non-Peters variety ;-) )