added traits support for the parent function

This commit is contained in:
Fabien Potencier
2011-09-22 12:03:40 +02:00
parent 56f82db1a1
commit d101a05976
9 changed files with 98 additions and 10 deletions
+8 -4
View File
@@ -1628,22 +1628,26 @@ is ignored. To avoid name conflicts, you can rename imported blocks:
{% block title %}{% endblock %}
{% block content %}{% endblock %}
Renaming also allows you to simulate inheritance by calling the "parent" block
(like what you would have done with ``parent()``):
The ``parent()`` function automatically determines the correct inheritance
tree, so it can be used when overriding a block defined in an imported
template:
.. code-block:: jinja
{% extends "base.html" %}
{% use "blocks.html" with sidebar as parent_sidebar %}
{% use "blocks.html" %}
{% block sidebar %}
{{ block('parent_sidebar') }}
{{ parent() }}
{% endblock %}
{% block title %}{% endblock %}
{% block content %}{% endblock %}
In this example, ``parent()`` will correctly call the ``sidebar`` block from
the ``blocks.html`` template.
.. note::
You can use as many ``use`` statements as you want in any given template.