``block`` ========= .. versionadded:: 1.28 Using ``block`` with the ``defined`` test was added in Twig 1.28. .. versionadded:: 1.28 Support for the template argument was added in Twig 1.28. When a template uses inheritance and if you want to print a block multiple times, use the ``block`` function: .. code-block:: twig <title>{% block title %}{% endblock %}</title> <h1>{{ block('title') }}</h1> {% block body %}{% endblock %} The ``block`` function can also be used to display one block from another template: .. code-block:: twig {{ block("title", "common_blocks.twig") }} Use the ``defined`` test to check if a block exists in the context of the current template: .. code-block:: twig {% if block("footer") is defined %} ... {% endif %} {% if block("footer", "common_blocks.twig") is defined %} ... {% endif %} .. seealso:: :doc:`extends<../tags/extends>`, :doc:`parent<../functions/parent>`
Name | Type | Size | Permission | Actions |
---|---|---|---|---|
attribute.rst | File | 679 B | 0644 |
|
block.rst | File | 968 B | 0644 |
|
constant.rst | File | 686 B | 0644 |
|
country_timezones.rst | File | 799 B | 0644 |
|
cycle.rst | File | 546 B | 0644 |
|
date.rst | File | 1.3 KB | 0644 |
|
dump.rst | File | 1.63 KB | 0644 |
|
html_classes.rst | File | 899 B | 0644 |
|
include.rst | File | 2.42 KB | 0644 |
|
index.rst | File | 213 B | 0644 |
|
max.rst | File | 403 B | 0644 |
|
min.rst | File | 402 B | 0644 |
|
parent.rst | File | 562 B | 0644 |
|
random.rst | File | 1.2 KB | 0644 |
|
range.rst | File | 1.2 KB | 0644 |
|
source.rst | File | 852 B | 0644 |
|
template_from_string.rst | File | 1.27 KB | 0644 |
|