mirror of
https://github.com/twigphp/Twig.git
synced 2026-09-21 07:37:43 +00:00
added traits support for the parent function
This commit is contained in:
+8
-4
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user