summaryrefslogtreecommitdiff
path: root/docs/templates.rst
diff options
context:
space:
mode:
authorDavid Lord <davidism@gmail.com>2021-11-09 10:32:06 -0800
committerDavid Lord <davidism@gmail.com>2021-11-09 10:34:48 -0800
commita6162daeca116e81ca8a390ed36b3c67aea33671 (patch)
tree869b79df64fa886949c523c417e284db9e8057b7 /docs/templates.rst
parent369ff03e090668b2366a7222a22def078bec7cb8 (diff)
downloadjinja2-a6162daeca116e81ca8a390ed36b3c67aea33671.tar.gz
rewrite docs about extending template objects
Diffstat (limited to 'docs/templates.rst')
-rw-r--r--docs/templates.rst25
1 files changed, 17 insertions, 8 deletions
diff --git a/docs/templates.rst b/docs/templates.rst
index a90f8bd..237a46b 100644
--- a/docs/templates.rst
+++ b/docs/templates.rst
@@ -587,17 +587,26 @@ When combined with ``scoped``, the ``required`` modifier must be placed
Template Objects
~~~~~~~~~~~~~~~~
-.. versionchanged:: 2.4
+``extends``, ``include``, and ``import`` can take a template object
+instead of the name of a template to load. This could be useful in some
+advanced situations, since you can use Python code to load a template
+first and pass it in to ``render``.
+
+.. code-block:: python
+
+ if debug_mode:
+ layout = env.get_template("debug_layout.html")
+ else:
+ layout = env.get_template("layout.html")
-If a template object was passed in 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::
+ user_detail = env.get_template("user/detail.html", layout=layout)
+
+.. code-block:: jinja
- {% extends layout_template %}
+ {% extends layout %}
-Previously, the `layout_template` variable had to be a string with
-the layout template's filename for this to work.
+Note how ``extends`` is passed the variable with the template object
+that was passed to ``render``, instead of a string.
HTML Escaping