@@ -738,6 +738,8 @@ There is also a non-HTML syntax that can be used:
738
738
{% block footer %}... footer content{% endblock %}
739
739
{% endcomponent %}
740
740
741
+ .. _embedded-components-context :
742
+
741
743
Context / Variables Inside of Blocks
742
744
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
743
745
@@ -801,10 +803,7 @@ When overriding the ``alert_message`` block, you have access to the ``message``
801
803
</twig:block>
802
804
</twig:SuccessAlert>
803
805
804
- .. versionadded :: 2.13
805
-
806
- The ability to refer to the scope of higher components via the ``outerScope ``
807
- variable was added in 2.13.
806
+ .. _embedded-components-outerScope :
808
807
809
808
As mentioned before, variables from lower components are merged with those from
810
809
upper components. When you need access to some properties or functions from higher
@@ -825,6 +824,11 @@ components, that can be done via the ``outerScope...`` variable:
825
824
{{ outerScope.this.someProp }} {# references a "someProp" prop from SuccessAlert #}
826
825
{% endcomponent %}
827
826
827
+ .. versionadded :: 2.13
828
+
829
+ The ability to refer to the scope of higher components via the ``outerScope ``
830
+ variable was added in 2.13.
831
+
828
832
You can keep referring to components higher up as well. Just add another ``outerScope ``.
829
833
Remember though that the ``outerScope `` reference only starts once you're INSIDE the (embedded) component.
830
834
@@ -842,6 +846,8 @@ Remember though that the ``outerScope`` reference only starts once you're INSIDE
842
846
{% endblock %}
843
847
{% endcomponent %}
844
848
849
+ .. _embedded-components-outerBlocks :
850
+
845
851
Inheritance & Forwarding "Outer Blocks"
846
852
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
847
853
@@ -1563,9 +1569,33 @@ listen to ``PreMountEvent`` or ``PostMountEvent``.
1563
1569
Nested Components
1564
1570
-----------------
1565
1571
1566
- It's totally possible to include components as part of the contents of another
1567
- component. When you do this, all components render independently. The only
1568
- caveat is that you cannot mix the Twig syntax and the :ref: `HTML syntax <component_html_syntax >`
1572
+ It's possible to include components inside another component:
1573
+
1574
+ .. code-block :: html+twig
1575
+
1576
+ <twig:SomeComponent>
1577
+ {% for i in 1..10 %}
1578
+ <twig:AnotherComponent>
1579
+ {{ i }}
1580
+ </twig:AnotherComponent>
1581
+ {% endfor %}
1582
+ </twig:SomeComponent>
1583
+
1584
+ When you do this, each component is rendered independently, but there are some
1585
+ important caveats:
1586
+
1587
+ #. As :ref: `explained above <embedded-components-context >`, the variables of a
1588
+ component are merged with the variables of its parent component. Variables
1589
+ with the same name (e.g. ``this `` or ``computed ``) are overridden by the
1590
+ inner component;
1591
+ #. The original parent component variables are available via the special
1592
+ :ref: `outerScope variable <embedded-components-outerScope >`, so you can, for
1593
+ example, call ``outerScope.this.someFunction() ``;
1594
+ #. The contents of blocks defined in parent components are available via the
1595
+ special :ref: `outerBlocks variable <embedded-components-outerBlocks >`, so you
1596
+ can call ``block(outerBlocks.someBlockName) ``.
1597
+
1598
+ Finally, you cannot mix the Twig syntax and the :ref: `HTML syntax <component_html_syntax >`
1569
1599
when using nested components:
1570
1600
1571
1601
.. code-block :: html+twig
@@ -1599,8 +1629,9 @@ when using nested components:
1599
1629
{% endblock %}
1600
1630
{% endcomponent %}
1601
1631
1602
- If you're using `Live Components `_, then there *are * some guidelines related to
1603
- how the re-rendering of parent and child components works. Read `Live Nested Components `_.
1632
+ If you're using `Live Components `_, there *are * additional guidelines related
1633
+ to how parent and child components are re-rendered. See `Live Nested Components `_
1634
+ for details.
1604
1635
1605
1636
Configuration
1606
1637
-------------
0 commit comments