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

[3.9] Cannot assign the output of a custom tag to a variable using set #4039

Closed
MauricioFauth opened this issue Apr 18, 2024 · 2 comments · Fixed by #4062
Closed

[3.9] Cannot assign the output of a custom tag to a variable using set #4039

MauricioFauth opened this issue Apr 18, 2024 · 2 comments · Fixed by #4062

Comments

@MauricioFauth
Copy link
Contributor

After Twig 3.9.0, it's not possible to capture the output of a custom tag (that uses echo) and assign it to a variable using set.

A {% set variable %}{% trans 'value' %}{% endset %} B {{ variable }} C

With Twig 3.9.0+, that will print:

A value B  C

Instead of the expected:

A  B value C

It works as expected if the custom tag output is not the only content, for example:

A {% set variable %}some {% trans 'value' %}{% endset %} B {{ variable }} C

Outputs:

A  B some value C
titouanmathis added a commit to studiometa/twig-toolkit that referenced this issue Apr 18, 2024
Twig 3.9.0 introduced a new `yield` usage, breaking the `html_element`
tag node.

See twigphp/Twig#4039.
@fabpot
Copy link
Contributor

fabpot commented Apr 29, 2024

If the trans tag comes from Symfony, I've tried A {% set variable %}{% trans %}value{% endtrans %}{% endset %} B {{ variable }} C and it works as expected. Can you confirm that you're not using the trans tag from Symfony? If yes, then, I would need something I can reproduce.

@MauricioFauth
Copy link
Contributor Author

MauricioFauth commented Apr 29, 2024

It was from phpmyadmin/twig-i18n-extension that is a fork of Twig's I18nExtension.

I "fixed" this in the phpmyadmin/twig-i18n-extension 4.1.1 by adding support for yield if Twig 3.9 is detected, but phpmyadmin/twig-i18n-extension 4.1.0 doesn't work with Twig 3.9 because of that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging a pull request may close this issue.

2 participants