|
This adds two new actions to text/template: {{block}} and {{fill}}. This is how it works:
The content of a {{block}} action is displayed normally when a template is called directly. But when the template is inserted into another one using a {{fill}} action, the blocks can be replaced by blocks with the same name defined in the fill action.
Nutshell example:
{{define "Base"}}
<p>{{block "body"}}
A body.
{{end}}</p>
{{end}}
{{define "Home"}}
{{fill "Base"}}
{{block "body"}}
Another body.
{{end}}
{{end}}
{{end}}
{{define "Item"}}
{{fill "Base"}}
{{block "body"}}
And yet another body.
{{end}}
{{end}}
{{end}}
Executing the templates "Base", "Home" and "Item" results in: "<p>A body</p>", "<p>Another body</p>" and "<p>And yet another body</p>".
Essentially, {{fill}} behaves like a {{template}} action with body: {{block}} actions that replace the ones in the called template.
The idea is to use this to define layout skeletons filled in different templates. In practical terms this works like "template inheritance" in Django templates -- but this schema is based in composition rather than inheritance.
Try the new actions in the package:
code.google.com/p/sadbox/template
|