[svn] added "renderinclude" function (highly experimental)
authorArmin Ronacher <armin.ronacher@active-4.com>
Tue, 22 May 2007 09:27:11 +0000 (11:27 +0200)
committerArmin Ronacher <armin.ronacher@active-4.com>
Tue, 22 May 2007 09:27:11 +0000 (11:27 +0200)
--HG--
branch : trunk

jinja/defaults.py
jinja/utils.py

index 1a0e10cf137a8bf5ef0bc2df8454196b31a7a56b..18bcc8f62712a4c0cce7bae1242a2d10a188ad18 100644 (file)
@@ -11,7 +11,7 @@
 from jinja.filters import FILTERS as DEFAULT_FILTERS
 from jinja.tests import TESTS as DEFAULT_TESTS
 from jinja.utils import debug_helper, safe_range, generate_lorem_ipsum, \
-     watch_changes
+     watch_changes, render_included
 
 
 __all__ = ['DEFAULT_FILTERS', 'DEFAULT_TESTS', 'DEFAULT_NAMESPACE']
@@ -21,5 +21,6 @@ DEFAULT_NAMESPACE = {
     'range':                safe_range,
     'debug':                debug_helper,
     'lipsum':               generate_lorem_ipsum,
-    'watchchanges':         watch_changes
+    'watchchanges':         watch_changes,
+    'renderincluded':       render_included
 }
index c900b3784fcd02c383521ddd1673003234ecd440..627498306754cf1d17e74dc53c589bc52867e9b2 100644 (file)
@@ -241,6 +241,17 @@ def watch_changes(env, context, iterable, *attributes):
 watch_changes.jinja_context_callable = True
 
 
+def render_included(env, context, template_name):
+    """
+    Works like djangos {% include %} tag. It doesn't include the
+    template but load it independently and renders it to a string.
+    """
+    #XXX: ignores parent completely!
+    tmpl = env.get_template(template_name)
+    return tmpl.render(context.to_dict())
+render_included.jinja_context_callable = True
+
+
 # python2.4 and lower has a bug regarding joining of broken generators.
 # because of the runtime debugging system we have to keep track of the
 # number of frames to skip. that's what RUNTIME_EXCEPTION_OFFSET is for.