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

KevinL darius@obsidian.com.au
02 Jun 2002 12:46:45 +1000


On Sun, 2002-06-02 at 08:36, Page Page wrote:
> I like page templates because they permit uncomplicated
> cooperation with designers who don't know DTML and/or
> use drag-and-drop composers. Newbie I am, however, I see
> a few problems here, and I hope they stem from my ignorance.
> 
> 1.) Can page templates be "modularized"?
> DTML is great for assembling pages from re-usable blocks,
> i.e. dtml_standard_header, dtml_standard_footer. 
> I have not found an equivalent facility for page templates.
> Is there any?

There seems to be two ways to manage this stuff.  Metal is great, but
will push you into building "well-formed" modules - so instead of
standard_header and standard_footer, you build a standard_page macro,
which contains both, and feed your content into that.  It's a bit wierd,
but it works well.

Alternately, for complete "blocks", you can simply call other ptl from
inside your ptl pages.  They still have to be well-formed, but that's a
nice way to build, for example, a ptl page that renders one particular
object (the example I have in my head is from our system, where we have
invoices for customers, and we display them in multiple places - so we
have a "render_invoice" ptl, that gets called from a few different
spots, where-ever we want the invoice to appear).

The big trick with all of this is making well-formed pages, even when
you're making little snippets - opened tags have to be closed, etc.  It
just means you need to approach your layout a little differently, is
all.

> 
> 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.

Not sure what you mean here.  You're talking about tal:attributes
values, and working out what they should be?

> 
> 3.) Dynamic pages
> This is a more generic newbie question, since it is not
> confined to the realms of page templates. Let's say my site
> sports a uniform layout for hundreds of used-car ads.
> Each ad gets its own page which content is pulled from a
> data-base on the fly. This content is wrapped into identical
> hooks for banner ads, a header, footer and navigation bar.
> Without Zope one sets up a table of content with a link
> to each ad; each link calls a cgi-script with some id for
> the data-base in the QUERY_STRING. This requires the script
> to assemble the page, send the cgi-ahoy (content-type: text/blabla)
> and the <html> for the page. Is there a Zope-ish way to do
> this? I have not even found a way to access a page template
> from a script for reading. The data for Zope-objects seems
> to be pickled in files.db.

Normally, from what you've said above, you'd either:

a) keep everything in ptl/zope pages - write a zsql method that uses
your zope database adaptor to make the request, call that from a python
script or ptl page that wraps the results in html (lots of tal:repeat
stuff), feed the whole lot through a macro that wraps it in
header/footer banners etc.

b) write a python product - said product would know how to talk to the
database, pull the appropriate data out, and return it ready to be
wrapped up as above.

"a" is probably sufficient for what you're looking at, I suspect.  "b"
adds some complexity that may not be warranted.  The basic approach is
similar in both cases, however.  You'd browse to a page like:

http://your.host.com/display/ad?adID=24

/display/ad would take the adID, call another ptl or python script that
would call the zsql method to get the ad details, wrap the details in
html, then return.  /display/ad would pipe the whole lot through a macro
that adds banners etc.

Sound appropriate?

KJL