From: Armin Ronacher Date: Sat, 14 Apr 2007 23:12:20 +0000 (+0200) Subject: [svn] added missing documentation file X-Git-Tag: 2.0rc1~355 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=74cd0176a4281bd66b90c111b0b247c3eb97f1ad;p=jinja2.git [svn] added missing documentation file --HG-- branch : trunk --- 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()