[et-mgmt-tools] Cheetah raw/endraw (was: Templating...)

Michael DeHaan mdehaan at redhat.com
Mon Jun 11 19:16:50 UTC 2007

Aaron Lippold wrote:
> /s/When cheetah naturally/When I don't escape the ${var} cheetah/g
... snip ...

If you have large blocks of shell in %pre and %post, rather than 
escaping them in Cheetah, I just discovered you can exclose them in #raw 
... #endraw blocks.


If you have template variables (--ksmeta) that you want to access from 
shell, you can assign them to shell variables in your %pre or %post 
sections and
then use them from inside the raw sections.

See example:



from Cheetah.Template import *
# notice how I am setting foo and bar such that they'll be available in 
the raw section...
data = """#errorCatcher Echo
\$foo = $foo
\$bar = $bar
if [ $(grep \" /home \" #echo "${FSTAB} | grep -c \"nosuid\") -eq 0 ]; 
# use $foo
# use $bar
search = {
   "foo" : "gleep",
   "bar" : "gloop"
t = Template(source=data, searchList=[search])
print str(t)


This seems to me a lot cleaner than doing the escaping or needing to 
understand the escaping rules.


More information about the et-mgmt-tools mailing list