Behavior on non definded name in Cheetah
Paolo Pantaleo
paolopantaleo at gmail.com
Wed Aug 2 07:06:01 EDT 2006
2006/8/2, Stephan Diehl <stephan.diehl at gmx.net>:
> Paolo Pantaleo wrote:
> > [I hope I am posting to the right place]
> >
> > I have a cheetah template something like this:
> >
> > x is: $x
> > y is: $y
> > z is: $z
> >
> > [Actually more complicated]
> >
> > If for example $y is not defined I get an exception and the parsing
> > of the template stops. Is there any way to substitute $y with an emty
> > string and making cheeta going on with parsing?
> >
> > Thnx
> > PAolo
> >
>
> http://cheetahtemplate.org/docs/users_guide_html_multipage/language.namemapper.missing.html
> --
> http://mail.python.org/mailman/listinfo/python-list
>
Actually I wanted to keep things simple for who writes the template,
so I am using this workaround: I define a class
class ClassMapper:
def __init__(self,dict={}):
self.__dict=dict
def getValue(self,str):
try:
return self.__dict[str]
except KeyError:
return ""
x=ClassMapper(dict)
Template(definition, searchList=[{"info":x.getValue}])
so the user should do
$info("name")
Maybe I could define a class that implements a dictionary and doesn''t
raise an exception for a key not present... but it seems to
complicated.
PAolo
--
if you have a minute to spend please visit my photogrphy site:
http://mypic.co.nr
More information about the Python-list
mailing list