Skip to content

Commit 6ac23cb

Browse files
committed
Update documentation
1 parent 6db02ad commit 6ac23cb

File tree

1 file changed

+17
-11
lines changed

1 file changed

+17
-11
lines changed

src/TwigComponent/doc/index.rst

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -951,41 +951,47 @@ When overriding the ``alert_message`` block, you have access to the ``message``
951951
{% endblock %}
952952
{% endcomponent %}
953953
954-
Sometimes, you may want to override a block of a deeply nested component and you need access to
955-
some properties or functions from higher components. That can be done via the ``this.parent...`` hierarchy:
954+
As mentioned before, variables from lower components are merged with those from upper components. When you need
955+
access to some properties or functions from higher components, that can be done via the ``outerScope...`` variable:
956956

957957
.. code-block:: twig
958958
959959
{# templates/SuccessAlert.html.twig #}
960-
{% component Alert with { type: 'success' } %}
961-
{{ this.parent.someFunction }} {# this refers to SuccessAlert #}
960+
{% set name = 'Fabien' %}
961+
{% set message = 'Hello' %}
962+
{% component Alert with { type: 'success', name: 'Bart' } %}
963+
Hello {{ name }} {# name = Bart #}
964+
965+
{{ message }} {{ outerScope.name }} {# message = 'Hello', name = Fabien #}
966+
967+
{{ outerScope.this.someFunction }} {# this refers to SuccessAlert #}
962968
963-
{{ this.parent.someProp }} {# references a "someProp" prop from SuccessAlert #}
969+
{{ outerScope.this.someProp }} {# references a "someProp" prop from SuccessAlert #}
964970
{% endcomponent %}
965971
966-
To keep the generic Alert component unaware of the ``someProp`` prop it is better to use ``this.parent``
972+
To keep the generic Alert component unaware of the ``someProp`` prop it is better to use ``outerScope.this``
967973
instead of passing that info along via Alert's attributes.
968974

969-
You can keep referring to 'grand parents' as well. Just add another ``parent``.
970-
Remember though that the parent reference only starts once you're INSIDE the (embedded) component.
975+
You can keep referring to components higher up as well. Just add another ``outerScope``.
976+
Remember though that the ``outerScope`` reference only starts once you're INSIDE the (embedded) component.
971977

972978
.. code-block:: twig
973979
974980
{# templates/FancyProfileCard.html.twig #}
975981
{% component Card %}
976982
{% block header %}
977-
{% component Alert with { message: this.parent.someProp } %} {# not yet INSIDE the Alert template #}
983+
{% component Alert with { message: outerScope.this.someProp } %} {# not yet INSIDE the Alert template #}
978984
{% block content %}
979985
{{ message }} {# same value as below, indirectly refers to FancyProfileCard::someProp #}
980-
{{ this.parent.parent.someProp }} {# directly refers to FancyProfileCard::someProp #}
986+
{{ outerScope.outerScope.this.someProp }} {# directly refers to FancyProfileCard::someProp #}
981987
{% endblock %}
982988
{% endcomponent %}
983989
{% endblock %}
984990
{% endcomponent %}
985991
986992
.. versionadded:: 2.12
987993

988-
The ability to refer to higher components via the ``this.parent`` syntax was added in 2.12.
994+
The ability to refer to the scope of higher components via the ``outerScope`` variable was added in 2.12.
989995

990996
Component HTML Syntax
991997
---------------------

0 commit comments

Comments
 (0)