RE: [Cheetahtemplate-discuss] Bug in NameMapper and global variables?
Brought to you by:
rtyler,
tavis_rudd
From: Brian B. <bri...@se...> - 2006-05-04 08:34:18
|
Thanks for your help. Comments inline: > Use #attr instead of '#set global'. This sets a class > attribute in the child template, which can be read by the > parent. I'm assuming the value is constant in each subclass; > it doesn't change at runtime or per-instance. Unfortunately in my case the variable can (sometimes) change per instance, so #attr isn't appropriate. > Another strategy, which may not be appropriate in this case > but is good to remember, is to pass the value as a method argument. In this case it could work but would mean having to instantiate a variable in lots of templates instead of one place (a burden I didn't want to put onto the template designers). I solved the problem by putting the variable into the searchList when instantiating the Templates. While this works perfectly well in this case, I can't help feeling there should have been a way to do it directing in the templates rather than in the python code calling the templates. > I've never used '#set global' and can't think of a case where > it's necessary. Is anybody else using it? It's kind of > confusing so maybe we should deprecate it. Anything in the > searchList is global across subtemplates, so why not put the > value there instead? Also, in Cheetah 2 there's '#set > moduleglobal' which is simpler and more Pythonic than '#set global'. Hmm, I've not seen #set moduleglobal, but from what I've seen of #set global I'm getting convinced that it's bugged. Last time I thought I'd found a bug in a feature (errorCatcher) it turned out nobody was using it anyway and I think it was deprecated. Perhaps I have a knack for this :-) (Which reminds me, I think #errorCatcher is in the new 2.0 documentation, is that right?) Brian |