File tree Expand file tree Collapse file tree 1 file changed +36
-0
lines changed Expand file tree Collapse file tree 1 file changed +36
-0
lines changed Original file line number Diff line number Diff line change @@ -951,6 +951,42 @@ 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:
956
+
957
+ .. code-block :: twig
958
+
959
+ {# templates/SuccessAlert.html.twig #}
960
+ {% component Alert with { type: 'success' } %}
961
+ {{ this.parent.someFunction }} {# this refers to SuccessAlert #}
962
+
963
+ {{ this.parent.someProp }} {# references a "someProp" prop from SuccessAlert #}
964
+ {% endcomponent %}
965
+
966
+ To keep the generic Alert component unaware of the ``someProp `` prop it is better to use ``this.parent ``
967
+ instead of passing that info along via Alert's attributes.
968
+
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.
971
+
972
+ .. code-block :: twig
973
+
974
+ {# templates/FancyProfileCard.html.twig #}
975
+ {% component Card %}
976
+ {% block header %}
977
+ {% component Alert with { message: this.parent.someProp } %} {# not yet INSIDE the Alert template #}
978
+ {% block content %}
979
+ {{ message }} {# same value as below, indirectly refers to FancyProfileCard::someProp #}
980
+ {{ this.parent.parent.someProp }} {# directly refers to FancyProfileCard::someProp #}
981
+ {% endblock %}
982
+ {% endcomponent %}
983
+ {% endblock %}
984
+ {% endcomponent %}
985
+
986
+ .. versionadded :: 2.12
987
+
988
+ The ability to refer to higher components via the ``this.parent `` syntax was added in 2.12.
989
+
954
990
Component HTML Syntax
955
991
---------------------
956
992
You can’t perform that action at this time.
0 commit comments