You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{% macro message_formatter(message) %} <strong>{{ message }}</strong> {% endmacro %} <twig:Alert> {# ❌ this won't work #} {% from_selfimportmessage_formatter %} {# ✅ this works as expected #} {% from'path/of/this/template.html.twig'importmessage_formatter %} {{ message_formatter('...') }} </twig:Alert>
Using _self. is so convenient for calling macros defined in the same template that I think we should improve this to avoid the template import. Some proposals:
TwigComponentRFCRFC = Request For Comments (proposals about features that you want to be discussed)
1 participant
Converted from issue
This discussion was converted from issue #2979 on October 03, 2025 02:30.
Heading
Bold
Italic
Quote
Code
Link
Numbered list
Unordered list
Task list
Attach files
Mention
Reference
Menu
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
As explained in the docs (https://symfony.com/bundles/ux-twig-component/current/index.html#using-macros-in-components) you cannot use Twig macros inside components unless you import the full template explicitly:
Using
_self.
is so convenient for calling macros defined in the same template that I think we should improve this to avoid the template import. Some proposals:_self
viaouterScope
:outerMacros
variable with the macros of the current template, similar to the existingouterBlocks
:Thanks!
Beta Was this translation helpful? Give feedback.
All reactions