Yes. Take a look at http://chameleon.repoze.org/docs/latest/metal.html
--
Daniel Nouri
http://danielnouri.org
What I do is I wrap template variables into a TemplateAPI object and
send it along to every template. You can also use the IBeforeRender
event to provide globals to the template, such as your master
template.
> 2. Besides looking cumbersome with that (define|use) (macro|slot) stuff,
> what I had in mind would render illegal XML. The inherited layout template
> should contain the complete page structure, including the opening HTML tag
> and the doctype. Afaiu all content I want to reference elsewhere has to be
> enclosed in a define-macro block. So the needed doctype and HTML tag had to
> be inside the define-macro block as well. But I cannot use the define-macro
> attribute, because its namespace is defined inside that block.
Look at the example in the docs that you linked to. When you
use-macro, you'll get the whole layout page and override only those
blocks that you're interested in with fill-slot. Anything in the
inheriting template that's not inside fill-slot will be ignored.
> In mako this looks intuitive and easy:
> templates/layouts/default.mak:
> <!DOCTYPE html>
> <html>
> <body>${next.body()}</body>
> </html>
> templates/index.mak
> <%inherit file="layouts/default.mak" />
> <p>blah</p>
> Or am I missing sth?
This looks indeed more intuitive than metal for what you're looking for.
In your layout, use define-macro on the HTML element:
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:tal="http://xml.zope.org/namespaces/tal"
xmlns:metal="http://xml.zope.org/namespaces/metal"
define-macro="content">
<div id="content">
<span metal:define-slot="content">content</span>
</div>
<p>misc in default</p>
</html>
Same with use-macro in your index.pt:
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:tal="http://xml.zope.org/namespaces/tal"
xmlns:metal="http://xml.zope.org/namespaces/metal"
metal:use-macro="default.macros['content']">
<span metal:fill-slot="content">Hello from ZPT</span>
<p>misc in index</p>
</html>
The resulting HTML will be all of layout.pt, with only the "content"
slot replaced.
HTH,
Daniel
Not sure. nxml mode complains anyway.
> 2. Chameleon ZPT seem not to bother about that, because I can remove the
> xmlns-declarations altogether.
> 3. Chameleon ZPT also does not complain if I use a fantasy tag.
> Unfortunately, still I find no way to put a valid doctype declaration into
> the layout template.
> Code example: http://paste.pocoo.org/show/348195/
The doctype goes to the top of your index.pt
The doctype goes to the top of your index.pt