Skip to content

Commit 49ec396

Browse files
committed
minor #2432 [Doc] Mention how to work with Twig macros in Twig Components (javiereguiluz)
This PR was squashed before being merged into the 2.x branch. Discussion ---------- [Doc] Mention how to work with Twig macros in Twig Components | Q | A | ------------- | --- | Bug fix? | no | New feature? | no | Issues | - | License | MIT Made during the #SymfonyHackday Commits ------- 45f825e [Doc] Mention how to work with Twig macros in Twig Components
2 parents db6db8d + 45f825e commit 49ec396

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

src/TwigComponent/doc/index.rst

+15
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,21 @@ You can even give the block default content. See
365365
:ref:`Passing HTML to Components via Block <embedded-components>`
366366
for more info.
367367

368+
The only limitation when defining contents inside a component using the HTML syntax
369+
is that you cannot import macros using the ``_self`` keyword. You must always use
370+
the full template path:
371+
372+
.. code-block:: html+twig
373+
374+
<twig:Alert>
375+
{# ❌ this won't work #}
376+
{% from _self import message_formatter %}
377+
{# ✅ this works as expected #}
378+
{% from 'some/path/template.html.twig' import message_formatter %}
379+
380+
{{ message_formatter('...') }}
381+
</twig:Alert>
382+
368383
Fetching Services
369384
-----------------
370385

0 commit comments

Comments
 (0)