Skip to content
Myr

the environment template loading functions now transparently

Before adoption: this commit came in with the history the project adopted, so no landing records it.

pass through a template object if it was passed to it. This makes it possible to import or extend from a template object that was passed to the template. --HG-- branch : trunk

authored by Armin Ronacher · committed by Armin Ronacher · parent df2907e · Browse files · 4 files+43 added−1 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

4 files+43 added−1 removed

  • other:+43 added−1 removed

4 files+43 added−1 removed

modified:docs/templates.rst+24 added
407 unmodified lines
408409When overriding a block the `scoped` modifier does not have to be provided.410411412Template Objects413~~~~~~~~~~~~~~~~414415.. versionchanged:: 2.4416417If a template object was passed to the template context you can418extend from that object as well. Assuming the calling code passes419a layout template as `layout_template` to the environment, this420code works::421422 {% extends layout_template %}423424Previously the `layout_template` variable had to be a string with425the layout template's filename for this to work.426427428HTML Escaping429-------------430431When generating HTML from templates, there's always a risk that a variable will
359 unmodified lines
791792 {% include ['page_detailed.html', 'page.html'] %}793 {% include ['special_sidebar.html', 'sidebar.html'] ignore missing %}794795.. versionchanged:: 2.4796 If a template object was passed to the template context you can797 include that object using `include`.798799.. _import:800801Import802~~~~~~
46 unmodified lines
849850Macros and variables starting with one ore more underscores are private and851cannot be imported.852853.. versionchanged:: 2.4854 If a template object was passed to the template context you can855 import from that object.856857858.. _import-visibility:859860Import Context Behavior861-----------------------
449 unmodified lines
modified:jinja2/testsuite/api.py+8 added-1 removed
15 unmodified lines
16from jinja2.testsuite import JinjaTestCase1718from jinja2 import Environment, Undefined, DebugUndefined, \19 StrictUndefined, UndefinedError, Template, meta, \20 is_undefined20 is_undefined, Template21from jinja2.utils import Cycler2223env = Environment()24
43 unmodified lines
6869 expr = env.compile_expression("42 + foo")70 assert expr(foo=42) == 847172 def test_template_passthrough(self):73 t = Template('Content')74 assert env.get_template(t) is t75 assert env.select_template([t]) is t76 assert env.get_or_select_template([t]) is t77 assert env.get_or_select_template(t) is t787980class MetaTestCase(JinjaTestCase):8182 def test_find_undeclared_variables(self):83 ast = env.parse('{% set foo = 42 %}{{ bar + foo }}')
117 unmodified lines
modified:jinja2/environment.py+6 added
550 unmodified lines
551552 If the template does not exist a :exc:`TemplateNotFound` exception is553 raised.554 """555 if isinstance(name, Template):556 return name557 if parent is not None:558 name = self.join_path(name, parent)559 return self._load_template(name, self.make_globals(globals))560
9 unmodified lines
570 raise TemplatesNotFound(message=u'Tried to select from an empty list '571 u'of templates.')572 globals = self.make_globals(globals)573 for name in names:574 if isinstance(name, Template):575 return name576 if parent is not None:577 name = self.join_path(name, parent)578 try:579 return self._load_template(name, globals)
11 unmodified lines
591 .. versionadded:: 2.3592 """593 if isinstance(template_name_or_list, basestring):594 return self.get_template(template_name_or_list, parent, globals)595 elif isinstance(template_name_or_list, Template):596 return template_name_or_list597 return self.select_template(template_name_or_list, parent, globals)598599 def from_string(self, source, globals=None, template_class=None):600 """Load a template from a string. This parses the source given and
338 unmodified lines
modified:CHANGES+5 added
3 unmodified lines
4Version 2.45-----------6(codename to be selected, release date to be decided)78- the environment template loading functions now transparently9 pass through a template object if it was passed to it. This10 makes it possible to import or extend from a template object11 that was passed to the template.1213Version 2.314-----------15(3000 Pythons, released on February 10th 2010)16
134 unmodified lines