Re: [Cheetahtemplate-discuss] Really basic searchList question
Brought to you by:
rtyler,
tavis_rudd
From: <ir...@ms...> - 2002-08-30 06:09:46
|
On Fri, Aug 30, 2002 at 01:41:00AM -0400, Edmund Lian wrote: > I have a template that looks like this: > > #from PageTemplate import PageTemplate > #extends PageTemplate > #def mainPanel > $test > #end def mainPanel > > > t = Template(file="/web/dev/webware/Contexts/elian/TByProperty.tmpl", \ > searchList= [{'test': 'Hello']) That's a syntax error, but if you add a "}" after 'Hello', it's correct both per Python and per Cheetah. > self.writeln(t) writeln needs to write str(t) and not just t. > I get a "NotFound: test" error It works for me. I put the template in x.tmpl and made an empty superclass PageTemplate.py: from Cheetah.Template import Template class PageTemplate(Template): pass % python Python 2.2 (#10, Jan 2 2002, 01:37:36) [GCC 2.95.4 20011006 (Debian prerelease)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> from Cheetah.Template import Template >>> t = Template(file="x.tmpl", \ ... searchList= [{'test': 'Hello'}]) >>> print t >>> There's no output because you didn't ask for any; #def is silent. If the superclass prints $mainPanel somewhere, that would solve that. If you add text and still don't get any output, try adding "#implements respond". Regarding your NotFound error, that's a mystery. Try adding #import pprint $pprint.pformat($searchList) to verify 'test' shows up. > > If I insert an instance of the following object into the searchList, I get > > from Cheetah.Template import Template > from WebKit.Page import Page > > class MyClass(object): > def __init__(self): > self.test = 'Attribute' > def test(self): > return 'Method call' > > class TestProperty(Page): > def writeContent(self): > obj = MyClass() > t = Template(file="/path/to/my/template/TByProperty.tmpl", \ > searchList= [obj]) > self.writeln(t) > > > I still get the same NotFound error. >>> class MyClass(object): ... def __init__(self): ... self.test = 'Attribute' ... def test(self): ... return 'Method call' ... >>> obj = MyClass() >>> t = Template("$test", searchList=[obj]) >>> print t Attribute >>> -- -Mike (Iron) Orr, ir...@ms... (if mail problems: ms...@oz...) http://iron.cx/ English * Esperanto * Russkiy * Deutsch * Espan~ol |