Skip to content

Commit

Permalink
Reword and reposition
Browse files Browse the repository at this point in the history
  • Loading branch information
sneakyvv committed Aug 25, 2023
1 parent c34455d commit b783c39
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 37 deletions.
66 changes: 31 additions & 35 deletions src/LiveComponent/doc/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2453,40 +2453,6 @@ The parent-child system is *smart*. And with a few tricks
(:ref:`such as the key prop for lists of embedded components <rendering-quirks-with-list-of-embedded-components>`),
you can make it behave exactly like you need.

.. _passing-blocks:

Passing Blocks to Components
----------------------------

Passing blocks to Live components works completely the same way you would `pass blocks for Twig Components`_. Except...

When re-rendering a Live component, only the template for thàt component is rendered. The blocks defined in the
"parent" template are grabbed via the smart Twig templating system, but the context from the parent template is *NOT*
available during re-rendering. So, keep in mind to not refer to any outer context variables within blocks of a live component.

This won't work:

.. code-block:: twig
{# templates/some_page.html.twig #}
{% set message = 'Outer context only works on first render' %}
{% component Alert %}
{% block content %}{{ message }}{% endblock %}
{% endcomponent %}
Local variables do remain available:

.. code-block:: twig
{# templates/some_page.html.twig #}
{% component Alert %}
{% block content %}
{% set message = 'this works during re-rendering!' %}
{{ message }}
{% endblock %}
{% endcomponent %}
.. _child-component-independent-rerender:

Each component re-renders independent of one another
Expand Down Expand Up @@ -2945,6 +2911,36 @@ To fix this, you have two options:
}
}

.. _passing-blocks:

Passing Content (Blocks) to Components
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Passing content via blocks to Live components works completely the same way you would `pass content to Twig Components`_.
Except with one important difference: when a component is re-rendered, any variables defined only in the
"outside" template will note be available. For example, this won't work:

.. code-block:: twig
{# templates/some_page.html.twig #}
{% set message = 'Variables from the outer part of the template are only available during the initial render' %}
{% component Alert %}
{% block content %}{{ message }}{% endblock %}
{% endcomponent %}
Local variables do remain available:

.. code-block:: twig
{# templates/some_page.html.twig #}
{% component Alert %}
{% block content %}
{% set message = 'this works during re-rendering!' %}
{{ message }}
{% endblock %}
{% endcomponent %}
Advanced Functionality
----------------------

Expand Down Expand Up @@ -3161,4 +3157,4 @@ bound to Symfony's BC policy for the moment.
.. _`the traditional collection type`: https://symfony.com/doc/current/form/form_themes.html#fragment-naming-for-collections
.. _`How to Work with Form Themes`: https://symfony.com/doc/current/form/form_themes.html
.. _`Symfony's built-in form theming techniques`: https://symfony.com/doc/current/form/form_themes.html
.. _`pass blocks for Twig Components`: https://symfony.com/bundles/ux-twig-component/current/index.html#passing-blocks
.. _`pass content to Twig Components`: https://symfony.com/bundles/ux-twig-component/current/index.html#passing-blocks
6 changes: 4 additions & 2 deletions src/TwigComponent/doc/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1006,8 +1006,10 @@ This requires Twig 3.7.0 or higher:

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

Passing Blocks to your Component
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.. _passing-blocks:

Passing Content (Blocks) to Components
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

You can also pass content directly to your component:

Expand Down

0 comments on commit b783c39

Please sign in to comment.