@@ -951,41 +951,47 @@ When overriding the ``alert_message`` block, you have access to the ``message``
951
951
{% endblock %}
952
952
{% endcomponent %}
953
953
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 :
956
956
957
957
.. code-block :: twig
958
958
959
959
{# 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 #}
962
968
963
- {{ this.parent .someProp }} {# references a "someProp" prop from SuccessAlert #}
969
+ {{ outerScope.this .someProp }} {# references a "someProp" prop from SuccessAlert #}
964
970
{% endcomponent %}
965
971
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 ``
967
973
instead of passing that info along via Alert's attributes.
968
974
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.
971
977
972
978
.. code-block :: twig
973
979
974
980
{# templates/FancyProfileCard.html.twig #}
975
981
{% component Card %}
976
982
{% 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 #}
978
984
{% block content %}
979
985
{{ 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 #}
981
987
{% endblock %}
982
988
{% endcomponent %}
983
989
{% endblock %}
984
990
{% endcomponent %}
985
991
986
992
.. versionadded :: 2.12
987
993
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.
989
995
990
996
Component HTML Syntax
991
997
---------------------
0 commit comments