summaryrefslogtreecommitdiff
path: root/docs/users_guide_2_src/eg_5.py
diff options
context:
space:
mode:
Diffstat (limited to 'docs/users_guide_2_src/eg_5.py')
-rw-r--r--docs/users_guide_2_src/eg_5.py25
1 files changed, 25 insertions, 0 deletions
diff --git a/docs/users_guide_2_src/eg_5.py b/docs/users_guide_2_src/eg_5.py
new file mode 100644
index 0000000..551f9c0
--- /dev/null
+++ b/docs/users_guide_2_src/eg_5.py
@@ -0,0 +1,25 @@
+from Cheetah.Template import Template
+
+# ways of using Python to process values after
+#retrieval. 1. Sets a new variable then uses it,
+#2. Uses pure Python function to set new variable
+#3. Cheetah calls function directly
+#4. Extended ${} syntax without function call
+
+tmpl = """
+
+#set $value1 = $value.replace(' ','-')
+1. $value1
+<% def change(x):
+ return x.replace(' ','-')
+%>
+#set $value1 = change($value)
+2. $value1
+3. $change($value)
+4. ${value.replace(' ','-')}
+"""
+NS = [ {'value':'this and that'}]
+
+#compile and fill the template
+t = Template(source=tmpl, namespaces=NS)
+print t.respond()