@@ -2453,6 +2453,40 @@ The parent-child system is *smart*. And with a few tricks
2453
2453
(:ref: `such as the key prop for lists of embedded components <rendering-quirks-with-list-of-embedded-components >`),
2454
2454
you can make it behave exactly like you need.
2455
2455
2456
+ .. _passing-blocks :
2457
+
2458
+ Passing Blocks to Components
2459
+ ----------------------------
2460
+
2461
+ Passing blocks to Live components works completely the same way you would `pass blocks for Twig Components `_. Except...
2462
+
2463
+ When re-rendering a Live component, only the template for thàt component is rendered. The blocks defined in the
2464
+ "parent" template are grabbed via the smart Twig templating system, but the context from the parent template is *NOT *
2465
+ available during re-rendering. So, keep in mind to not refer to any outer context variables within blocks of a live component.
2466
+
2467
+ This won't work:
2468
+
2469
+ .. code-block :: twig
2470
+
2471
+ {# templates/some_page.html.twig #}
2472
+ {% set message = 'Outer context only works on first render' %}
2473
+
2474
+ {% component Alert %}
2475
+ {% block content %}{{ message }}{% endblock %}
2476
+ {% endcomponent %}
2477
+
2478
+ Local variables do remain available:
2479
+
2480
+ .. code-block :: twig
2481
+
2482
+ {# templates/some_page.html.twig #}
2483
+ {% component Alert %}
2484
+ {% block content %}
2485
+ {% set message = 'this works during re-rendering!' %}
2486
+ {{ message }}
2487
+ {% endblock %}
2488
+ {% endcomponent %}
2489
+
2456
2490
.. _child-component-independent-rerender :
2457
2491
2458
2492
Each component re-renders independent of one another
@@ -3127,3 +3161,4 @@ bound to Symfony's BC policy for the moment.
3127
3161
.. _`the traditional collection type` : https://symfony.com/doc/current/form/form_themes.html#fragment-naming-for-collections
3128
3162
.. _`How to Work with Form Themes` : https://symfony.com/doc/current/form/form_themes.html
3129
3163
.. _`Symfony's built-in form theming techniques` : https://symfony.com/doc/current/form/form_themes.html
3164
+ .. _`pass blocks for Twig Components` : https://symfony.com/bundles/ux-twig-component/current/index.html#passing-blocks
0 commit comments