Skip to content

Commit ae5a458

Browse files
committed
Add simple example of outerBlocks without nested components to ease in
1 parent 111ac3a commit ae5a458

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

src/TwigComponent/doc/index.rst

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -841,6 +841,24 @@ Inheritance & Forwarding "Outer Blocks"
841841

842842
The ``outerBlocks`` variable was added in 2.10.
843843

844+
Consider this simple example to explain the basic usage of ``outerBlocks`` which serves as a
845+
means to refer to blocks defined in the same template:
846+
847+
.. code-block:: html+twig
848+
849+
{% extends 'base.html.twig' %}
850+
851+
{% block call_to_action %}<strong>Attention! Free Puppies!</strong>{% endblock %}
852+
853+
{% block body %}
854+
{% component Alert %}
855+
{% block content %}{{ block(outerBlocks.call_to_action) }}{% endblock %}
856+
{% endcomponent %}
857+
{% endblock %}
858+
859+
Although this is not a super practical example. The ``outerBlocks`` variable becomes a lot
860+
more useful with nested components.
861+
844862
When passing blocks via the ``{% component %}`` syntax, there is one important thing
845863
to understand: the content behaves as if it lives in its **own**, independent template,
846864
which extends the component's template.

0 commit comments

Comments
 (0)