-----------
(codename to be selected, release date to be decided)
+- the environment template loading functions now transparently
+ 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.
+
Version 2.3
-----------
(3000 Pythons, released on February 10th 2010)
When overriding a block the `scoped` modifier does not have to be provided.
+Template Objects
+~~~~~~~~~~~~~~~~
+
+.. versionchanged:: 2.4
+
+If a template object was passed to the template context you can
+extend from that object as well. Assuming the calling code passes
+a layout template as `layout_template` to the environment, this
+code works::
+
+ {% extends layout_template %}
+
+Previously the `layout_template` variable had to be a string with
+the layout template's filename for this to work.
+
+
HTML Escaping
-------------
{% include ['page_detailed.html', 'page.html'] %}
{% include ['special_sidebar.html', 'sidebar.html'] ignore missing %}
+.. versionchanged:: 2.4
+ If a template object was passed to the template context you can
+ include that object using `include`.
+
.. _import:
Import
Macros and variables starting with one ore more underscores are private and
cannot be imported.
+.. versionchanged:: 2.4
+ If a template object was passed to the template context you can
+ import from that object.
+
.. _import-visibility:
If the template does not exist a :exc:`TemplateNotFound` exception is
raised.
"""
+ if isinstance(name, Template):
+ return name
if parent is not None:
name = self.join_path(name, parent)
return self._load_template(name, self.make_globals(globals))
u'of templates.')
globals = self.make_globals(globals)
for name in names:
+ if isinstance(name, Template):
+ return name
if parent is not None:
name = self.join_path(name, parent)
try:
"""
if isinstance(template_name_or_list, basestring):
return self.get_template(template_name_or_list, parent, globals)
+ elif isinstance(template_name_or_list, Template):
+ return template_name_or_list
return self.select_template(template_name_or_list, parent, globals)
def from_string(self, source, globals=None, template_class=None):
from jinja2 import Environment, Undefined, DebugUndefined, \
StrictUndefined, UndefinedError, Template, meta, \
- is_undefined
+ is_undefined, Template
from jinja2.utils import Cycler
env = Environment()
expr = env.compile_expression("42 + foo")
assert expr(foo=42) == 84
+ def test_template_passthrough(self):
+ t = Template('Content')
+ assert env.get_template(t) is t
+ assert env.select_template([t]) is t
+ assert env.get_or_select_template([t]) is t
+ assert env.get_or_select_template(t) is t
+
class MetaTestCase(JinjaTestCase):