Skip to content

Commit a62c813

Browse files
sneakyvvweaverryan
authored andcommitted
[TwigComponent][LiveComponent] Add Embedded Live Components doc
1 parent a3a1ae9 commit a62c813

File tree

2 files changed

+40
-4
lines changed

2 files changed

+40
-4
lines changed

src/LiveComponent/doc/index.rst

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2911,6 +2911,36 @@ To fix this, you have two options:
29112911
}
29122912
}
29132913

2914+
.. _passing-blocks:
2915+
2916+
Passing Content (Blocks) to Components
2917+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2918+
2919+
Passing content via blocks to Live components works completely the same way you would `pass content to Twig Components`_.
2920+
Except with one important difference: when a component is re-rendered, any variables defined only in the
2921+
"outside" template will not be available. For example, this won't work:
2922+
2923+
.. code-block:: twig
2924+
2925+
{# templates/some_page.html.twig #}
2926+
{% set message = 'Variables from the outer part of the template are only available during the initial render' %}
2927+
2928+
{% component Alert %}
2929+
{% block content %}{{ message }}{% endblock %}
2930+
{% endcomponent %}
2931+
2932+
Local variables do remain available:
2933+
2934+
.. code-block:: twig
2935+
2936+
{# templates/some_page.html.twig #}
2937+
{% component Alert %}
2938+
{% block content %}
2939+
{% set message = 'this works during re-rendering!' %}
2940+
{{ message }}
2941+
{% endblock %}
2942+
{% endcomponent %}
2943+
29142944
Advanced Functionality
29152945
----------------------
29162946

@@ -3127,3 +3157,4 @@ bound to Symfony's BC policy for the moment.
31273157
.. _`the traditional collection type`: https://symfony.com/doc/current/form/form_themes.html#fragment-naming-for-collections
31283158
.. _`How to Work with Form Themes`: https://symfony.com/doc/current/form/form_themes.html
31293159
.. _`Symfony's built-in form theming techniques`: https://symfony.com/doc/current/form/form_themes.html
3160+
.. _`pass content to Twig Components`: https://symfony.com/bundles/ux-twig-component/current/index.html#passing-blocks

src/TwigComponent/doc/index.rst

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -830,9 +830,11 @@ The ``with`` data is what's mounted on the component object.
830830
{% endblock %}
831831
{% endcomponent %}
832832

833-
.. note::
833+
.. versionadded:: 2.11
834834

835-
The ``{% component %}`` syntax *cannot* currently be used with LiveComponents.
835+
The ``{% component %}`` syntax can also be used with LiveComponents since 2.11.
836+
However, there are some caveats related to the context between parent and child
837+
components during re-rending. Read `Passing Blocks to Live Components`_.
836838

837839
Inheritance & Forwarding "Outer Blocks"
838840
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -1004,8 +1006,10 @@ This requires Twig 3.7.0 or higher:
10041006

10051007
<twig:Alert{{ ...myAttributes }} />
10061008

1007-
Passing Blocks to your Component
1008-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1009+
.. _passing-blocks:
1010+
1011+
Passing Content (Blocks) to Components
1012+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
10091013

10101014
You can also pass content directly to your component:
10111015

@@ -1121,5 +1125,6 @@ https://symfony.com/doc/current/contributing/code/bc.html
11211125
.. _`live component`: https://symfony.com/bundles/ux-live-component/current/index.html
11221126
.. _`Vue`: https://v3.vuejs.org/guide/computed.html
11231127
.. _`Live Nested Components`: https://symfony.com/bundles/ux-live-component/current/index.html#nested-components
1128+
.. _`Passing Blocks to Live Components`: https://symfony.com/bundles/ux-live-component/current/index.html#passing-blocks
11241129
.. _`embed tag`: https://twig.symfony.com/doc/3.x/tags/embed.html
11251130
.. _`Stimulus controller`: https://symfony.com/bundles/StimulusBundle/current/index.html

0 commit comments

Comments
 (0)