[ZPT] page layout by "including" objects

Ron Bickers rbickers-dated-997847843.142b17@logicetc.com
Tue, 7 Aug 2001 23:57:23 -0400


> -----Original Message-----
> From: zpt-admin@zope.org [mailto:zpt-admin@zope.org]On Behalf Of Ron
> Bickers
> Sent: Tuesday, August 07, 2001 7:59 PM
> To: ZPT List
> Subject: [ZPT] page layout by "including" objects

It's nice when I can answer my own questions, I think.  I'll give this one a
shot and someone can tell me if I've done something stupid or if there's a
better way.

> As an example, I have a Folder 'Quotes' with DTML documents that contain
> short text quotes, and a DMTL method 'view' in that folder as follows:
>
>   <table>
>     [stuff to make pretty table]
>       <td><dtml-var this></td>
>     [stuff to make pretty table]
>   </table>

A ZPT 'view' in place of the DTML method as follows:

<metal:div define-macro="viewquote">
<table>
  [pretty stuff]
    <td tal:content="here">Quote</td>
  [/pretty stuff]
</table>
</metal:div>

> I can then put something like the following in a DTML document
> 'randomquote':
>
>   <dtml-with "_.whrandom.choice(Quotes.objectValues())">
>     <dtml-var view>
>   </dtml-with>

ZPT 'randomquote':

<metal:div define-macro="quote">
  <tal:div define="here python:whrandom.choice(root.Quotes.objectValues())">
  <metal:div use-macro="root/Quotes/view/macros/viewquote">Random Quote
Table</metal:div>
  </tal:div>
</metal:div>

Q: Is it safe to redefine 'here' in the div block?

> Now anytime I want to add a random quote to my page, I just use <dtml-var
> randomquote>.

<metal:div use-macro="root/randomquote/macros/quote">My Random Quote
Table</metal:div>

Did I miss anything?  I suppose I could combine the two macros for
effeciency, but it should work either way.

_______________________

Ron Bickers
Logic Etc, Inc.