Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Doc] Mention how to work with Twig macros in Twig Components #2432

Merged
merged 1 commit into from
Dec 7, 2024

Conversation

javiereguiluz
Copy link
Member

Q A
Bug fix? no
New feature? no
Issues -
License MIT

Made during the #SymfonyHackday

@javiereguiluz javiereguiluz added docs Improvements or additions to documentation TwigComponent labels Dec 7, 2024
@carsonbot carsonbot added the Status: Needs Review Needs to be reviewed label Dec 7, 2024
Comment on lines 370 to 381
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>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a RST expert here, but don't you need to use .. code-block:: html+twig to correctly highlight this code block?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hugo, you are absolutely right. I just fixed it. Thanks.

@Kocal Kocal force-pushed the twig_component_docs branch from c99a6ed to 45f825e Compare December 7, 2024 18:05
@Kocal
Copy link
Member

Kocal commented Dec 7, 2024

Thanks Javier! :)

@Kocal Kocal merged commit 49ec396 into symfony:2.x Dec 7, 2024
2 checks passed
@smnandre
Copy link
Member

@javiereguiluz @Kocal

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 ?

@smnandre smnandre requested a review from Kocal December 10, 2024 05:14
@smnandre smnandre added the Status: Waiting Feedback Needs feedback from the author label Dec 10, 2024
@Kocal
Copy link
Member

Kocal commented Dec 10, 2024

Did something in particular made you guys think it was due to HTML syntax?

I don't think so.

@javiereguiluz do you have more info about that?

@javiereguiluz javiereguiluz deleted the twig_component_docs branch December 10, 2024 09:52
@javiereguiluz
Copy link
Member Author

OK, sorry for the confusion 😐 Should I create a new PR to revert these changes or can you revert it yourself? Thanks.

@Kocal
Copy link
Member

Kocal commented Dec 10, 2024

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 :/

@javiereguiluz
Copy link
Member Author

Changes reverted in #2437.

@smnandre
Copy link
Member

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.

❤️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs Improvements or additions to documentation Status: Needs Review Needs to be reviewed Status: Waiting Feedback Needs feedback from the author TwigComponent
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants