f5d683c73da628bdabade470f10c354ac5304297
[yaffs-website] / vendor / twig / twig / doc / functions / block.rst
1 ``block``
2 =========
3
4 .. versionadded: 1.28
5     Using ``block`` with the ``defined`` test was added in Twig 1.28.
6
7 .. versionadded: 1.28
8     Support for the template argument was added in Twig 1.28.
9
10 When a template uses inheritance and if you want to print a block multiple
11 times, use the ``block`` function:
12
13 .. code-block:: jinja
14
15     <title>{% block title %}{% endblock %}</title>
16
17     <h1>{{ block('title') }}</h1>
18
19     {% block body %}{% endblock %}
20
21 The ``block`` function can also be used to display one block of another
22 template:
23
24 .. code-block:: jinja
25
26     {{ block("title", "common_blocks.twig") }}
27
28 Use the ``defined`` test to check if a block exists in the context of the
29 current template:
30
31 .. code-block:: jinja
32
33     {% if block("footer") is defined %}
34         ...
35     {% endif %}
36
37     {% if block("footer", "common_blocks.twig") is defined %}
38         ...
39     {% endif %}
40
41 .. seealso:: :doc:`extends<../tags/extends>`, :doc:`parent<../functions/parent>`