Skip to content

Commit eedeadc

Browse files
committed
minor #2125 [Doc] Add some explanation about mixing Twig and HTML syntax in nested components (javiereguiluz)
This PR was squashed before being merged into the 2.x branch. Discussion ---------- [Doc] Add some explanation about mixing Twig and HTML syntax in nested components | Q | A | ------------- | --- | Bug fix? | no | New feature? | no | Issues | - | License | MIT Related to #2104 Commits ------- 6d674e2 [Doc] Add some explanation about mixing Twig and HTML syntax in nested components
2 parents 79b584f + 6d674e2 commit eedeadc

File tree

1 file changed

+40
-5
lines changed

1 file changed

+40
-5
lines changed

src/TwigComponent/doc/index.rst

Lines changed: 40 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,8 @@ You can control the template used via the ``AsTwigComponent`` attribute:
271271
You can also configure the default template directory for an entire
272272
namespace. See :ref:`Configuration <configuration>`.
273273

274+
.. _component_html_syntax:
275+
274276
Component HTML Syntax
275277
~~~~~~~~~~~~~~~~~~~~~
276278

@@ -1585,11 +1587,44 @@ listen to ``PreMountEvent`` or ``PostMountEvent``.
15851587
Nested Components
15861588
-----------------
15871589

1588-
It's totally possible to nest one component into another. When you do
1589-
this, there's nothing special to know: both components render
1590-
independently. If you're using `Live Components`_, then there
1591-
*are* some guidelines related to how the re-rendering of parent and
1592-
child components works. Read `Live Nested Components`_.
1590+
It's totally possible to include components as part of the contents of another
1591+
component. When you do this, all components render independently. The only
1592+
caveat is that you cannot mix the Twig syntax and the :ref:`HTML syntax <component_html_syntax>`
1593+
when using nested components:
1594+
1595+
.. code-block:: html+twig
1596+
1597+
{# ❌ this won't work because it mixes different syntaxes #}
1598+
<twig:Card>
1599+
{# ... #}
1600+
1601+
{% block footer %}
1602+
<twig:Button:Primary :isBlock="true">Edit</twig:Button:Primary>
1603+
{% endblock %}
1604+
</twig:Card>
1605+
1606+
{# ✅ this works because it only uses the HTML syntax #}
1607+
<twig:Card>
1608+
{# ... #}
1609+
1610+
<twig:block name="footer">
1611+
<twig:Button:Primary :isBlock="true">Edit</twig:Button:Primary>
1612+
</twig:block>
1613+
</twig:Card>
1614+
1615+
{# ✅ this also works because it only uses the Twig syntax #}
1616+
<twig:Card>
1617+
{# ... #}
1618+
1619+
<twig:block name="footer">
1620+
{% component 'Button:Primary' with {isBlock: true} %}
1621+
{% block content %}Edit{% endblock %}
1622+
{% endcomponent %}
1623+
</twig:block>
1624+
</twig:Card>
1625+
1626+
If you're using `Live Components`_, then there *are* some guidelines related to
1627+
how the re-rendering of parent and child components works. Read `Live Nested Components`_.
15931628

15941629
Configuration
15951630
-------------

0 commit comments

Comments
 (0)