On 8 May 2013 23:12, Mike Orr <[email protected]> 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

-- 
You received this message because you are subscribed to the Google Groups 
"pylons-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/pylons-discuss?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to