Skip to content

Commit

Permalink
minor symfony#2432 [Doc] Mention how to work with Twig macros in Twig…
Browse files Browse the repository at this point in the history
… 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
  • Loading branch information
Kocal committed Dec 7, 2024
2 parents db6db8d + 45f825e commit 49ec396
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/TwigComponent/doc/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,21 @@ You can even give the block default content. See
:ref:`Passing HTML to Components via Block <embedded-components>`
for more info.

The only limitation when defining contents inside a component using the HTML syntax
is that you cannot import macros using the ``_self`` keyword. You must always use
the full template path:

.. code-block:: html+twig

<twig:Alert>
{# ❌ this won't work #}
{% from _self import message_formatter %}
{# ✅ this works as expected #}
{% from 'some/path/template.html.twig' import message_formatter %}

{{ message_formatter('...') }}
</twig:Alert>

Fetching Services
-----------------

Expand Down

0 comments on commit 49ec396

Please sign in to comment.