RE: [Cheetahtemplate-discuss] Bug in NameMapper and global variables?
Brought to you by:
rtyler,
tavis_rudd
From: Brian B. <bri...@se...> - 2006-05-03 08:29:56
|
That sounds strange - surely a global variable should be global across all templates? However, if that's not something which is going to change, what's wrong with the following example? Shouldn't the global variable defined in the parent be made available to the child template and the other #def's in the parent template? ------ parent.tmpl ------- #set global globalVar="Global Name" #def func() $globalVar #end def ------ main2.py --------- from Cheetah import Template source = """#extends parent #implements respond $func() """ print Template.Template(source=source) ------ command line ------ Cheetah compile parent.tmpl python main2.py Traceback (most recent call last): File "main2.py", line 6, in ? print Template.Template(source=source) File "/usr/local/lib/python2.4/site-packages/Cheetah/Template.py", line 995, in __str__ def __str__(self): return getattr(self, mainMethName)() File "DynamicallyCompiledCheetahTemplate.py", line 87, in respond File "/tmp/c/parent.py", line 88, in func _v = VFFSL(SL,"globalVar",True) # '$globalVar' on line 4, col 2 NameMapper.NotFound: cannot find 'globalVar' -----Original Message----- From: Mike Orr [mailto:slu...@gm...] Sent: 02 May 2006 22:06 To: Brian Bird Cc: che...@li... Subject: Re: [Cheetahtemplate-discuss] Bug in NameMapper and global variables? On 5/2/06, Brian Bird <bri...@se...> wrote: > > > I've got a problem using a "#set global" in an intermediate template. > If I have a heirarchy of a grandparent (one.tmpl), a parent (two.tmpl) > and a child which extends the parent, I thought that any global > variable should be accessible from any of the templates. However, if I > set a global variable in two.tmpl as follows, I get a NotFound > exception. If the "#set global" is in either the grandparent or the > child class it works as I expected (ie. I get "Hi Global Name" as the output). I think "#set global" works only from the main template. There's a general rule in Cheetah that information passed down from the main template to subtemplates, but not the other way. This is to prevent subtemplates from messing up the main template's environment. (A subtemplate is any #def method that's called, any #include'd template, or any precompiled template invoked by a $placeholder.) -- Mike Orr <slu...@gm...> (ms...@oz... address is semi-reliable) |