From 74a7278e9c67b4745a1bd3fcbcaaf900bd050134 Mon Sep 17 00:00:00 2001 From: Armin Ronacher Date: Tue, 22 May 2007 11:27:11 +0200 Subject: [PATCH] [svn] added "renderinclude" function (highly experimental) --HG-- branch : trunk --- jinja/defaults.py | 5 +++-- jinja/utils.py | 11 +++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/jinja/defaults.py b/jinja/defaults.py index 1a0e10c..18bcc8f 100644 --- a/jinja/defaults.py +++ b/jinja/defaults.py @@ -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 } diff --git a/jinja/utils.py b/jinja/utils.py index c900b37..6274983 100644 --- a/jinja/utils.py +++ b/jinja/utils.py @@ -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. -- 2.26.2