<div id="content"> <p>{{ month_name }}</p>
<p>{{ obj1.station.location }}</p></div>def _getSearchList(self, encoding, timespan, default_binding): """Get the complete search list to be used by Jinja."""
# Get the basic search list timespan_start_tt = time.localtime(timespan.start) #JINJA: Changed to we return a dictionary not a list searchList = self.outputted_dict searchList['month_name'] = time.strftime("%b", timespan_start_tt) searchList['year_name'] = timespan_start_tt[0] searchList['encoding'] = encoding # Bind to the default_binding: db_lookup = self.db_binder.bind_default(default_binding)
# Then add the V3.X style search list extensions count = 0 for obj in self.search_list_objs: searchList["obj"+str(count)] = obj.get_extension_list(timespan, db_lookup) count += 1
pprint(searchList){'obj0': <weewx.jinjagenerator.Almanac object at 0x112c943d0>,
'obj1': <weewx.jinjagenerator.Station object at 0x113045990>,
'obj2': <weewx.tags.TimeBinder object at 0x113045e90>,
'obj3': <weewx.jinjagenerator.UnitInfo object at 0x113045a50>,
'obj4': <weewx.jinjagenerator.Extras object at 0x113045bd0>,
'SummaryByMonth': [],
'SummaryByYear': [],
'encoding': 'html_entities',
'month_name': 'May',
'year_name': 2015
}
http://www.cheetahtemplate.org/docs/users_guide_html_multipage/inheritanceEtc.block.html
Thanks again for the response.
The reason I was looking is that I have written three little extensions but actually embedding them into the different pages is just loooong. So was I hoping to create some basic block snippets that could then either be inherited or extended. I must admit I was surprised when it appeared Cheetah didn't do it.
Chris
4.6 Object-Oriented Documents
Because Cheetah documents are actually class definitions, templates may inherit from one another in a natural way, using regular Python semantics. For instance, consider this template, FrogBase.tmpl:
#def title
This document has not defined its title
#end def
#def htTitle
$title
#end def
<HTML><HEAD>
<TITLE>$title</TITLE>
</HEAD><BODY>
<H1>$htTitle</H1>
$body
</BODY></HTML>
And its subclassed document, Frog1.tmpl:
#from FrogBase import FrogBase
#extends FrogBase
#def title
The Frog Page
#end def
#def htTitle
The <IMG SRC="Frog.png"> page
#end def
#def body
... lots of info about frogs ...
#end def
This is a classic use of inheritance. The parent ``template'' is simply an abstract superclass. Each document specializes the output of its parent. For instance, here the parent defines $htTitle so that by default it's identical to whatever the$title is, but it can also be customized.
Can we do template snippets in Cheetah e.g. Create a header segment that we can share/import across all pages?
This seems a heck of a lot simpler than compiling templates.