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 10When a template uses inheritance and if you want to print a block multiple 11times, 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 21The ``block`` function can also be used to display one block from another 22template: 23 24.. code-block:: jinja 25 26 {{ block("title", "common_blocks.twig") }} 27 28Use the ``defined`` test to check if a block exists in the context of the 29current 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>` 42