[Zope] Using ZPT to include a file
Paul Winkler
pw_lists@slinkp.com
Wed, 18 Jun 2003 06:25:49 -0400
On Wed, Jun 18, 2003 at 12:29:11PM +0100, Simon Forster wrote:
> Respectfully, archive the old versions of the book. The new book's
> structure is sufficiently different that you don't know what you've
> read and what you haven't - irritating if you're halfway through the
> previous version of the book. And people like me HATE starting again
> from the beginning! Archiving the old versions would seem to be quite
> low fruit in terms of preventing new users from starting off on the
> wrong foot!
we were hoping that the 2.6 edition would be made "current" at the
same time as the release of zope 2.6, back in January.
Unfortunately this did not happen - I guess Chris has not had time.
I'm hoping the 2.6 edition is marked "current" before zope 2.7
comes out :-P
> Anyway, onto ?s. Firstly, a couple of generic ones:
>
> - As a rule, I'm taking it that Zope Page Templates (ZPTs) are the way
> to go rather than DTML when we're talking about HTML pages? This broad
> rule seems to be the takeout from the latest Zope Book.
There are a number of very capable, experienced zopatistas who would
disagree with this; DTML has its fans, ZPT has its detractors.
Speaking for myself, I generally prefer ZPT.
> - As another rule, all logic goes into Python Scripts? Pages don't show
> logic unless it's presentation logic (if new user, display <b>Welcome
> New User</b> type of thing).
Yes.
> I just want to make sure that I start out with good habits.
>
> A more specific ?:
>
> I've got an existing site I'll adapt to run in Zope. This site has been
> put together in a very structured manner so should translate to Zope
> quite smoothly. Unfortunately, I'm failing at the first page. The
> structure of the site is such that I have a bunch of folders inside the
> sites root folder. One of these folders (Welcome) contains the default
> site page. What I'd like to do is include the content of this page in
> the index_html page at the site root. As Zope works back up the
> namespace hierarchy, the logical (to me) tag <b
> tal:replace="Welcome/index_html">Welcome to LDML Ltd</b> returns an
> error. How do I get Zope to include pages found in sub-folders?
>
> Basic stuff but we've all got to start somewhere.
Yep. I suspect you've read and understood the first Page Templates
chapter of the Zope book. All your questions are addressed in the
"Advanced Page Templates" chapter, *and* in the ZPT reference appendix
of the 2.6 edition. A lot of material, to be sure, but you'll
get through it eventually :)
In ZPT you have to provide a namespace to search for your names,
unless they've been defined locally (i.e. in the template, and
in one of the current enclosing tags).
so that would be something like:
<b tal:replace="container/Welcome/index_html"> blah blah </b>
The "container" is one of the standard names available in
TALES expressions. Basically this means "look in this template's
container for something called Welcome."
However, note that content that is inserted with tal:replace or tal:content
will be quoted by default. probably not what you want in this case.
To prevent this, you can use "structure" like so:
<b tal:replace="structure container/Welcome/index_html"> blah blah </b>
Also note that it's not common practice to insert a whole page
like that in ZPT. Instead, we typically use METAL macros instead. e.g.
<b metal:use-macro="container/Welcome/index_html/macros/main"> blah blah </b>
... and then Welcome/index_html would contain a "main" macro definition,
e.g. if you want to use the whole page as a macro:
<html metal:define-macro="main">
...
</html>
Macros are well explained in detail (with lots more cool stuff like slots)
in the "Advanced Page Templates" chapter of the 2.6 edition.
--
Paul Winkler
http://www.slinkp.com
Look! Up in the sky! It's EXO MEGA SUPERVISOR!
(random hero from isometric.spaceninja.com)