These are all good ways to use Cheetah, but I like to compile the
templates in init rather then externally via cheetah compile. You lose
the ability to have templates use other templates as base clases.
(Although you can just cheetah compile the base class)
If you are already using the normal Webkit.page you can just override
the writeContent method:
ClientList = clientpool.keys()
self._actionDesc = '%s Messages for %s ' %
This will recompile the templates each run so you can play with them
It's easy to precompile them also:
def __init__(self, config,sect):
self.clientTemplate = Template(file="siteTemplate.tmpl")
self.employeeTemplate = Template(file="empTemplate.tmpl")
#self.compileTemplates() #<-- uncomment when developing
t = self.clientTemplate
t.data = getClientData()
t = self.employeeTemplate
t.clientList = getCleintList()
t.generic = getUniversalData()
A final idea is to use a cheetah template to populate a function called
in another template:
<head><title></title></head><body>TOP HEADERS GOES HERE
in the SitePage:
t = Template('SitePage.tmpl')
t.pageContents = self.getContents()
t = Template('pageData.tmpl')
return ' This is not a page '
You can combine these to write a complex template system that will
strain even Pythons ability to write understanable code.
> Peter Lyons wrote:
>> (...) The only other idea I had was to override __import__ in the
>> __init__.py module, and there I think you might be able to do
>> something less brutal by hooking into the import process, but I'm not
>> enough of a pythonista yet to investigate that one.
> i just tried this from python console:
> m = __import__('socket', globals(), locals(), )
> this import "socket" module a store in m. being a python newbie
> too i'm wondering is this can be used instead of exec(<python code>).
> '' This function is invoked by the import statement. It mainly exists
> so that you can replace it with another function that has a compatible
> interface, in order to change the semantics of the import statement. ''
>> I've only been using this approach for a brief period, and I like
>> it so far. I like that fact that I can change the way a page looks
>> by changing the template it inherits from without messing with the
>> business logic. The pure inheritence approach to combining Cheetah
>> and Webware was too confusing for me.
> same here, i tried a couple of different approaches but i never
> felt confortable with them. this makes more sense for me.
>> Big hunks of HTML inside a servlet just won't fly for me, and I hate
>> trying to do anything non-presentation with Cheetah syntax, so this
>> approach keeps me pretty happy.
> here at work i would like to introduce the "graphics guy" to valid
> HTML and CSS layouts so i have to pass clean templates to him. this could
> help the process a lot.
>> If I find anything particularly nice about this approach, or any
>> major flaws, I'll post them to the Cheetah list.
> This SF.net email is sponsored by: VM Ware
> With VMware you can run multiple operating systems on a single machine.
> WITHOUT REBOOTING! Mix Linux / Windows / Novell virtual machines at the
> same time. Free trial click here: http://www.vmware.com/wl/offer/345/0
> Webware-discuss mailing list
"I don't know what's wrong with my television set. I was getting
C-Span and the Home Shopping Network on the same station.
I actually bought a congressman."
- Bruce Baum