Cheetah templates overriding
Cheetah is a very good templating language, especially because it's the one (correct me if i'm wrong) to apply the Object-Oriented model to Documents. It can seem a bit weird at the beginning but when you get used to it, you can't live without it :-)
So, i was looking for a good way to overload template parts without pain, here is how (couldn't find the trick on Cheetah doc):
Assume you have a template Package/Page.tmpl like that:
#def footer This is my foot ! #end def
Create a Page_custom.tmpl template:
#extends Package.Page #def footer $Page.footer($self) Where's my mind ? (dixit the Pixies) #end def
You need to put a self variable in the template's searchList which is the Cheetah template instance itself :-)
I don't think that trick will work if you don't compile your templates to Python code.
#. phil on Fri Aug 12 14:16:57 2005
Good point Deelan ;)
Actually the same trick is used by the framework behind this blog, but with #defS instead of #blockS
See the basic template:
http://svn.pythonfr.org/public/alinea/Alinea/templates/SitePage.tmpl
And one custom template (the #extends is added a posteriori):
http://svn.pythonfr.org/public/alinea/Alinea/designs/redFlower/SitePage_c.tmpl

#. deelan on Fri Aug 12 13:27:27 2005
"I don't think that trick will work if you don't compile your templates to Python code."
Correct, actually you have to precompile the base class.
In Subway[1] we managed to automatically compile the whole template hierarchy upon request. Builiding web site using Cheetah and his #extends directive is great. As you have written you can write some default markup into parent template #blockS and then override only when you really need to. No more ugly includes :)
For example, base site.html:
http://subway.python-hosting.com/file/sandbox/bikini/view/site.html
and one view which overrides both "content" and "nav" #blocks:
http://subway.python-hosting.com/file/sandbox/bikini/view/entry/show.html
-- deelan
[1] http://subway.python-hosting.com/