Twig: Warning: Undefined variable $_v0 since 3.15
Hi,
Since twig 3.15, the base layout of easyadmin ( vendor/easycorp/easyadmin-bundle/templates/layout.html.twig ) triggers a warning at line 108 of the template : {{ item.label|trans }} .
The warning tells that the $_v0 variable is undefined in the compiled version of the twig template, here is the line :
// line 108
yield " ";
yield $this->env->getRuntime('Twig\Runtime\EscaperRuntime')->escape($this->extensions['Symfony\Bridge\Twig\Extension\TranslationExtension']->trans(CoreExtension::getAttribute($this->env, $this->source, $context["item"], "label", [], "any", false, false, false, 108), [], $_v0), "html", null, true);
yield "
And the full function from the compiled template :
// line 96
/**
* @return iterable<null|scalar|\Stringable>
*/
public function block_user_menu(array $context, array $blocks = []): iterable
{
$macros = $this->macros;
$__internal_5a27a8ba21ca79b61932376b2fa922d2 = $this->extensions["Symfony\\Bundle\\WebProfilerBundle\\Twig\\WebProfilerExtension"];
$__internal_5a27a8ba21ca79b61932376b2fa922d2->enter($__internal_5a27a8ba21ca79b61932376b2fa922d2_prof = new \Twig\Profiler\Profile($this->getTemplateName(), "block", "user_menu"));
$__internal_6f47bbe9983af81f1e7450e9a3e3768f = $this->extensions["Symfony\\Bridge\\Twig\\Extension\\ProfilerExtension"];
$__internal_6f47bbe9983af81f1e7450e9a3e3768f->enter($__internal_6f47bbe9983af81f1e7450e9a3e3768f_prof = new \Twig\Profiler\Profile($this->getTemplateName(), "block", "user_menu"));
// line 97
yield " ";
if ((Twig\Extension\CoreExtension::length($this->env->getCharset(), CoreExtension::getAttribute($this->env, $this->source, CoreExtension::getAttribute($this->env, $this->source, (isset($context["ea"]) || array_key_exists("ea", $context) ? $context["ea"] : (function () { throw new RuntimeError('Variable "ea" does not exist.', 97, $this->source); })()), "userMenu", [], "any", false, false, false, 97), "items", [], "any", false, false, false, 97)) > 0)) {
// line 98
yield " <li><hr class=\"dropdown-divider\"></li>
";
// line 99
$context['_parent'] = $context;
$context['_seq'] = CoreExtension::ensureTraversable(CoreExtension::getAttribute($this->env, $this->source, CoreExtension::getAttribute($this->env, $this->source, (isset($context["ea"]) || array_key_exists("ea", $context) ? $context["ea"] : (function () { throw new RuntimeError('Variable "ea" does not exist.', 99, $this->source); })()), "userMenu", [], "any", false, false, false, 99), "items", [], "any", false, false, false, 99));
$context['loop'] = [
'parent' => $context['_parent'],
'index0' => 0,
'index' => 1,
'first' => true,
];
if (is_array($context['_seq']) || (is_object($context['_seq']) && $context['_seq'] instanceof \Countable)) {
$length = count($context['_seq']);
$context['loop']['revindex0'] = $length - 1;
$context['loop']['revindex'] = $length;
$context['loop']['length'] = $length;
$context['loop']['last'] = 1 === $length;
}
foreach ($context['_seq'] as $context["_key"] => $context["item"]) {
// line 100
yield " <li>
";
// line 101
if ((CoreExtension::getAttribute($this->env, $this->source, $context["item"], "isMenuSection", [], "any", false, false, false, 101) && !CoreExtension::getAttribute($this->env, $this->source, $context["loop"], "first", [], "any", false, false, false, 101))) {
// line 102
yield " <hr class=\"dropdown-divider\">
";
} elseif ( !CoreExtension::getAttribute($this->env, $this->source, // line 103
$context["item"], "isMenuSection", [], "any", false, false, false, 103)) {
// line 104
yield " <a href=\"";
yield $this->env->getRuntime('Twig\Runtime\EscaperRuntime')->escape(CoreExtension::getAttribute($this->env, $this->source, $context["item"], "linkUrl", [], "any", false, false, false, 104), "html", null, true);
yield "\" class=\"dropdown-item user-action ";
yield $this->env->getRuntime('Twig\Runtime\EscaperRuntime')->escape(CoreExtension::getAttribute($this->env, $this->source, $context["item"], "cssClass", [], "any", false, false, false, 104), "html", null, true);
yield "\"
target=\"";
// line 105
yield $this->env->getRuntime('Twig\Runtime\EscaperRuntime')->escape(CoreExtension::getAttribute($this->env, $this->source, $context["item"], "linkTarget", [], "any", false, false, false, 105), "html", null, true);
yield "\" rel=\"";
yield $this->env->getRuntime('Twig\Runtime\EscaperRuntime')->escape(CoreExtension::getAttribute($this->env, $this->source, $context["item"], "linkRel", [], "any", false, false, false, 105), "html", null, true);
yield "\"
referrerpolicy=\"origin-when-cross-origin\">
";
// line 107
if ( !Twig\Extension\CoreExtension::testEmpty(CoreExtension::getAttribute($this->env, $this->source, $context["item"], "icon", [], "any", false, false, false, 107))) {
yield $this->env->getRuntime('Symfony\UX\TwigComponent\Twig\ComponentRuntime')->render("ea:Icon", ["name" => CoreExtension::getAttribute($this->env, $this->source, $context["item"], "icon", [], "any", false, false, false, 107)]);
}
// line 108
yield " ";
yield $this->env->getRuntime('Twig\Runtime\EscaperRuntime')->escape($this->extensions['Symfony\Bridge\Twig\Extension\TranslationExtension']->trans(CoreExtension::getAttribute($this->env, $this->source, $context["item"], "label", [], "any", false, false, false, 108), [], $_v0), "html", null, true);
yield "
</a>
";
}
// line 111
yield " </li>
";
++$context['loop']['index0'];
++$context['loop']['index'];
$context['loop']['first'] = false;
if (isset($context['loop']['revindex0'], $context['loop']['revindex'])) {
--$context['loop']['revindex0'];
--$context['loop']['revindex'];
$context['loop']['last'] = 0 === $context['loop']['revindex0'];
}
}
$_parent = $context['_parent'];
unset($context['_seq'], $context['_key'], $context['item'], $context['_parent'], $context['loop']);
$context = array_intersect_key($context, $_parent) + $_parent;
// line 113
yield " ";
}
// line 114
yield " ";
$__internal_6f47bbe9983af81f1e7450e9a3e3768f->leave($__internal_6f47bbe9983af81f1e7450e9a3e3768f_prof);
$__internal_5a27a8ba21ca79b61932376b2fa922d2->leave($__internal_5a27a8ba21ca79b61932376b2fa922d2_prof);
yield from [];
}
I rolled back to 3.14.2 and all works again.
Thanks
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 1
- Comments: 56 (27 by maintainers)
Commits related to this issue
- fix: Downgrade Twig to 3.14 Twig 3.15+ breaks EasyAdmin for some unknown reasons. Let's stick on 3.14 until EasyAdmin has fixed up their problem. https://github.com/EasyCorp/EasyAdminBundle/issues/6... — committed to database-playground/app-sf by pan93412 2 years ago
- bug #59059 [TwigBridge] generate conflict-free variable names (xabbuh) This PR was merged into the 7.2 branch. Discussion ---------- [TwigBridge] generate conflict-free variable names | Q ... — committed to symfony/symfony by xabbuh 2 years ago
- bug #59059 [TwigBridge] generate conflict-free variable names (xabbuh) This PR was merged into the 7.2 branch. Discussion ---------- [TwigBridge] generate conflict-free variable names | Q ... — committed to symfony/twig-bridge by xabbuh 2 years ago
@fabpot
And maybe it would not happen if you stopped introducing breaking changes into minor versions. Using the weekend excuse as a way to hide the fact that you don’t care about us is disrespectful. I will say again in case today you are ready to listen: just emit a major version whenever you introduce breaking changes. We are not your beta testers.
Be prepared for the “acceptable breaking change” excuse.
How is that inappropriate? It is exactly the excuse that your team used about another closed issue. Is this is inappropriate here, it was also inappropriate when your team used it.
Also note that this issue is still closed. If someone was looking at it, it would have been reopened.
Please, be respectful. This comment is inappropriate, even more so as @xabbuh commented that he was looking at it.
Symfony 7.2.1 has been released.
Maybe because the discussion happened during the week-end?
I can confirm that I see the error on my side too with
@LaurentMarquet this is a known problem of Symfony 7.2.0.
The bug has been fixed here: https://github.com/symfony/symfony/pull/59059 but it won’t be available until Symfony 7.2.1 is released.
@pan93412 yes, it’d be very useful to us if you reported this issue when you found it. Next time, please do. Don’t worry about reporting the issue in the “wrong” repository; we’ll guide you, if needed, to open the issue in the most appropriate repository.
About https://symfony.com/slack activity, I can tell you that it’s more active than ever so you can use that too if you prefer it. Thanks.
@xabbuh yes, your change fixed the issue to me 🎉
Now I have SF 7.2.0 + Twig 3.16.0 + EA 4.18.0 and it’s working 🙌 Thanks a lot 🙇
I am looking into it.
@pan93412 done
Thank you all for confirming.
I managed to get it to work, thank you !
Can everyone affected by this issue please check if symfony/symfony#59059 fixes it?
This closure was not fixed as mentioned above.
@fabpot, the issue is still actual.
Closing as this has been fixed already as mentioned above.
It works for me, thank you ! 🎼
@ericmorand this bug was not caused by a BC break at all. We did a refactoring in the implementation of
{% trans_default_domain %}insymfony/twig-bridgeand the new implementation had a bug (not intended at all) in a case that was not covered by an integration test of the feature (new tests have also been added to prevent this to happen again in the future). The reason why downgrading Twig also fixed the issue is because the internal implementation of Symfony switches between 2 implementations depending on the version of Twig to avoid reporting a deprecation warning, and the bug was only in 1 of them, not in both.Hi, has someone found a solution? Because using SF 7.2.0, Twig 3.16.0 and EasyAdmin 4.20.0 I still have the same problem
SF 7.2.0, Twig 3.15.0 / 3.16.0, EasyAdmin 4.18.0 - fix works
Fix works for me with SF 7.2.0, Twig 3.16.0, EA 4.18.0
Mine issue also gone for SF 7.2.0 + Twig 3.16.0 + EA 4.18.0. Thanks
In addition to the reproducer app, I just tested this on a real and complex Symfony app that was failing too, and the changes proposed by Christian fixed it too.
@q1t1 probably you did, but make sure to run
rm -fr var/cache/*andsymfony server:stop && symfony serve -dafter changing that file invendor/symfony/twig-bridge/NodeVisitor/TranslationDefaultDomainNodeVisitor.phpThe
composer.lockindeed indicates that it is on Twig 3.16.0:https://github.com/javiereguiluz/ea-bug-reproducer/blob/0467a4bb1a9a37e28b1a091f6509b1521d2217bb/composer.lock#L7773-L7779
Note that I am using the latest Twig and
symfony/twig-bridge(6cc64f2357382540eeac5b2f66fc44fd34298693 and https://github.com/symfony/twig-bridge/commit/9958f5a5b6640734fe4b24c18897191f77a02c61), and it is also reproducible.@javiereguiluz Can you check that you have version 3.16.0?
@alexndlm the jobs is asking for it: https://github.com/EasyCorp/EasyAdminBundle/actions/runs/12086509610/job/33705948476#step:6:1
6.4as version constraint only allows 6.4.0 as matching version.For now, I cannot create the Tets app.
Could you please check this https://github.com/EasyCorp/EasyAdminBundle/actions/runs/12086509610/job/33705948788
The interesting thing is that for
devdevs, it works.Yes, #4452 has the exact same error in one of the comments, the issue title was not meaningful for my use case sorry ! I’m going to test it