On 8 May 2013 23:12, Mike Orr <
slugg...@gmail.com> wrote:
> 'self' maps straightforwardly to Chameleon's slots, but how do you do the
> equivalent of 'next' and 'parent'? For instance, if some page templates want
> to put the base content in an unusual order, and others want to overrride it
> completely, but you don't want to define duplicate content at multiple
> levels.
The pattern that's usually used is:
<metal:block fill-slot="content">
...
<metal:block define-slot="content">
...
</metal:block>
...
</metal:block>
This would be a template that sits in-between a master template and
the top-level template.
> Also, can I provide a title in the page template and use it as part of the
> title in the site template?
Yep –
<head>
<title metal:define-slot="title">${page_title|string:not sure}</title>
</head>
You can then fill this slot from anywhere in the "chain" of templates
that use and extend each other.
> Page: <title>My Title</title>
> Site: <title>${page_title} | SiteName</title>
You do need to use ``metal:fill=slot``.
> Or would I have to do something monsterous like this?
>
> Site: <title><title metal:define-slot="title" tal:omit-tag="1">Default
> Title</title></title>
> Page: <title metal:fill-slot="title">Page Title</title>
I would probably just define the slot on the <title> element itself –
or alternatively, use a <metal:block ... /> construct (note that the
term "block" is just often used, it doesn't carry special meaning).
> One, can I nest the <title> tag like this? Two, can I define a slot on one
> tag but fill it on a different tag, or does it have to be the same tag name?
> If it's different, which tag name has precedence?
You can define two slots with the same name and fill it with a single
expression, yes. That's pretty useful for things like the page title
where you often want to apply it to both <title> and <h1>.
\malthe