[Zope] ZPT tutorial

J Cameron Cooper zope-l at jcameroncooper.com
Tue Jun 21 15:13:21 EDT 2005


  John Poltorak wrote:

> On Tue, Jun 21, 2005 at 07:04:48PM +0100, Peter Bengtsson wrote:
>
>>>> How about the 2 chapters in the Zope book?
>>>
>>>
>>> I just don't find this book very helpful at all. It's written as a 
>>> manual
>>> rather than tutorial and reminds me of a book which explains how to 
>>> chop
>>> down a tree if you are interested in putting up some bookshelves.
>>>
>>> What I did find useful, though, was this worked example of how to put
>>> together a simple application:-
>>>
>>> http://www.plope.com/Books/2_7Edition/SimpleExamples.stx#1-6
>>>
>>> That was much more useful than anything else I've come across so. Just
>>> wish there were a few more examples.
>>>
>>
>> Interesting. If you like examples, be sure to get familiar with 
>> Zopelabs.com (zope cookbook)
>
>
> It probably is very useful, but I know I'd get hopelessly lost because 
> there is just so much stuff on it. Most of the newbie stuff about 
> macros is probably quite old by now so I doubt whether I'd find it 
> with a sequential browse through the Cookbook.
> It's disappointing to find that the link from Newbies under the ZOPE 
> section does not function.
>
> What I really need is something like a ZPT macro which defines a 
> header and footer and leaves a slot in the middle for my own content. 
> I don't  expect to be able to write my own macro for quite a while - 
> too many pitfalls... I'm not even sure is that is how I should be 
> approaching writing a home page.

You think it is harder than it is. I can show you by no more than
copy/paste from the ZMI help system.

The macro page (from Help! > Zope Help > ZPT Reference >
metal:define-slot) we will call 'master.html'::

       <p metal:define-macro="hello">
         Hello <b metal:define-slot="name">World</b>
       </p>

A client page (from metal:fill-slot)::

       <p metal:use-macro="container/master.html/macros/hello">
         Hello <b metal:fill-slot="name">Kevin Bacon</b>
       </p>

In CMF/Plone/etc, one would usually say 'context' instead of 'container'
because of the skins sytem.

It is not a great intellectual leap to replace "Hello" with header-type
page structure, and replace the whitespace after the slot with
footer-type structure.

         --jcc

-- 
"Building Websites with Plone"
http://plonebook.packtpub.com/

Enfold Systems, LLC
http://www.enfoldsystems.com


More information about the Zope mailing list