From 74cd0176a4281bd66b90c111b0b247c3eb97f1ad Mon Sep 17 00:00:00 2001 From: Armin Ronacher Date: Sun, 15 Apr 2007 01:12:20 +0200 Subject: [PATCH] [svn] added missing documentation file --HG-- branch : trunk --- docs/src/devrecipies.txt | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 docs/src/devrecipies.txt diff --git a/docs/src/devrecipies.txt b/docs/src/devrecipies.txt new file mode 100644 index 0000000..ae70226 --- /dev/null +++ b/docs/src/devrecipies.txt @@ -0,0 +1,38 @@ +======================= +Recipies For Developers +======================= + +Here some recipies for application developers. + + +Automagic Template Variables +============================ + +Python allows some magic stack manipulation which can be used to +pass variables to templates automatically. It's not a recommended +way to pass variables to templates but it can be useful for some +small generation scripts etc. + +Just subclass the environment and add an `autorender` function like +this: + +.. sourcecode:: python + + import sys + from jinja import Environment + + class AutoEnvironment(Environment): + + def autorender(self): + return self.render(sys._getframe(1).f_locals) + +You can use it now like this: + +.. sourcecode:: python + + foo_tmpl = env.get_template('foo.html') + + def foo(): + seq = range(10) + foo = "blub" + return foo_tmpl.autorender() -- 2.26.2