On Sat, May 4, 2013 at 12:21 AM, Malthe Borch <[email protected]> wrote:
> Chameleon makes it pretty easy I'd say to use a site template:
>
> <html metal:use-macro="load: ../master.pt">
> <div metal:fill-slot="content">
> <h1>${title}</h1>
> ...
> </div>
> </html>
>
> You can also use ``metal:extend-macro`` to make a linear
> specialization that keeps slots "fillable". For instance, you might
> specialize your "master.pt" template into a "content.pt" template that
> is then the basis of all content object views.
>
>
So the last part I don't understand is now to select parts of the macro
chain. For instance, I have a site template, section template, and page
template. I can specify fill content in the page template, but how do I do
the opposite, or access base content in the page template? Or is that
something you can't do in Chameleon?
So in Mako's base template I can use ${foo()} to get the local content,
${self.foo()} to get the top-level (subclass) content, or ${next.foo()} to
get the next level's content (either a intermediate template or the page
template). Likewise, in a page template I can use ${parent.foo()} to get
content from an ancestor (superclass) template.
'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.
Also, can I provide a title in the page template and use it as part of the
title in the site template?
Page: <title>My Title</title>
Site: <title>${page_title} | SiteName</title>
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>
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?
In Mako I do my titles like this:
===
## Site template
<title>${ht_title()}</title>
<h1>${title()}</title>
<%def name="ht_title">${title()}</%def>
<%def name="title">Default Title</%def>
## Page template.
<%inherit file="/base/site.html" />
## No title tag.
<%def name="title()">Page Title</%def>
===
--
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.