From 369ff03e090668b2366a7222a22def078bec7cb8 Mon Sep 17 00:00:00 2001 From: David Lord Date: Tue, 9 Nov 2021 10:13:10 -0800 Subject: remove reference to macro.defaults --- docs/templates.rst | 3 --- 1 file changed, 3 deletions(-) (limited to 'docs') diff --git a/docs/templates.rst b/docs/templates.rst index 6bdd6fc..a90f8bd 100644 --- a/docs/templates.rst +++ b/docs/templates.rst @@ -914,9 +914,6 @@ are available on a macro object: `arguments` A tuple of the names of arguments the macro accepts. -`defaults` - A tuple of default values. - `catch_kwargs` This is `true` if the macro accepts extra keyword arguments (i.e.: accesses the special `kwargs` variable). -- cgit v1.2.1 From a6162daeca116e81ca8a390ed36b3c67aea33671 Mon Sep 17 00:00:00 2001 From: David Lord Date: Tue, 9 Nov 2021 10:32:06 -0800 Subject: rewrite docs about extending template objects --- docs/templates.rst | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) (limited to 'docs') 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 -- cgit v1.2.1 From 0d1999067ba6a08389a309ce258eaf17fc3cc749 Mon Sep 17 00:00:00 2001 From: David Lord Date: Tue, 9 Nov 2021 10:50:35 -0800 Subject: document chained pow order --- docs/templates.rst | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'docs') diff --git a/docs/templates.rst b/docs/templates.rst index 237a46b..89958b8 100644 --- a/docs/templates.rst +++ b/docs/templates.rst @@ -1344,8 +1344,19 @@ but exists for completeness' sake. The following operators are supported: ``{{ '=' * 80 }}`` would print a bar of 80 equal signs. ``**`` - Raise the left operand to the power of the right operand. ``{{ 2**3 }}`` - would return ``8``. + Raise the left operand to the power of the right operand. + ``{{ 2**3 }}`` would return ``8``. + + Unlike Python, chained pow is evaluated left to right. + ``{{ 3**3**3 }}`` is evaluated as ``(3**3)**3`` in Jinja, but would + be evaluated as ``3**(3**3)`` in Python. Use parentheses in Jinja + to be explicit about what order you want. It is usually preferable + to do extended math in Python and pass the results to ``render`` + rather than doing it in the template. + + This behavior may be changed in the future to match Python, if it's + possible to introduce an upgrade path. + Comparisons ~~~~~~~~~~~ -- cgit v1.2.1