[Doc] Mention how to work with Twig macros in Twig Components#2432
Conversation
| the full template path: | ||
|
|
||
| <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> |
There was a problem hiding this comment.
Not a RST expert here, but don't you need to use .. code-block:: html+twig to correctly highlight this code block?
There was a problem hiding this comment.
Hugo, you are absolutely right. I just fixed it. Thanks.
c99a6ed to
45f825e
Compare
|
Thanks Javier! :) |
|
I feel this is how macros work and not something related to HTML syntax (nor components in general) I have tried quickly and none of this work: {# Classic embed #}
{% embed 'FooBar.html.twig' %}
{% block content %}
{% from _self import message_formatter as embed_formatter %}
{{ embed_formatter('.abc.') }}
{% endblock %}
{% endembed %}
{# Component template manually embeded #}
{% embed 'components/Alert.html.twig' %}
{% block content %}
❌ Will not work..
{% from _self import message_formatter as embed_formatter %}
{{ embed_formatter('.abc.') }}
{% endblock %}
{% endembed %}
{# Component tag with implicit "content" block #}
{% component 'Alert' %}
❌ Will not work..
{% from _self import message_formatter as component_formatter %}
{{ component_formatter('.abc.') }}
{% endcomponent %}
{# Component tag with explicit "content" block #}
{% component 'Alert' %}
{% block content %}
❌ Will not work..
{% from _self import message_formatter as component_formatter %}
{{ component_formatter('.abc.') }}
{% endblock %}
{% endcomponent %}Did something in particular made you guys think it was due to HTML syntax? Did i miss something here ? |
I don't think so. @javiereguiluz do you have more info about that? |
|
OK, sorry for the confusion 😐 Should I create a new PR to revert these changes or can you revert it yourself? Thanks. |
|
No worries, I should have been more careful too! Can you revert the PR? Usually I use the button "Revert" from GitHub UI, but I do not see it :/ |
|
Changes reverted in #2437. |
|
No need to be sorry of anything 😃 this kind of different behaviours between component tags and HTML syntax is quite frequent.. I was more afraid that something had changed recently / worked before "by chance" etc. ❤️ |
Made during the #SymfonyHackday