[TwigComponent] Simplify macros usage #3123
javiereguiluz
started this conversation in
RFC - Feature Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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:
{% macro message_formatter(message) %} <strong>{{ message }}</strong> {% endmacro %} <twig:Alert> {# ❌ this won't work #} {% from _self import message_formatter %} {# ✅ this works as expected #} {% from 'path/of/this/template.html.twig' import message_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:_selfviaouterScope:outerMacrosvariable with the macros of the current template, similar to the existingouterBlocks:Thanks!
Beta Was this translation helpful? Give feedback.
All reactions