diff --git a/src/TwigComponent/src/Twig/ComponentNode.php b/src/TwigComponent/src/Twig/ComponentNode.php index df735079570..c5a6b582243 100644 --- a/src/TwigComponent/src/Twig/ComponentNode.php +++ b/src/TwigComponent/src/Twig/ComponentNode.php @@ -19,6 +19,7 @@ use Twig\Node\Expression\AbstractExpression; use Twig\Node\Node; use Twig\Node\NodeOutputInterface; +use Twig\Template; /** * @author Fabien Potencier @@ -154,16 +155,29 @@ public function compile(Compiler $compiler): void if ($useYield) { $compiler->write('yield from '); } - $compiler - ->write('$this->loadTemplate(') - ->string($this->getAttribute('embedded_template')) - ->raw(', ') - ->repr($this->getTemplateName()) - ->raw(', ') - ->repr($this->getTemplateLine()) - ->raw(', ') - ->string($this->getAttribute('embedded_index')) - ->raw(')'); + + if (method_exists(Template::class, 'load')) { + $compiler + ->write('$this->load(') + ->string($this->getAttribute('embedded_template')) + ->raw(', ') + ->repr($this->getTemplateLine()) + ->raw(', ') + ->string($this->getAttribute('embedded_index')) + ->raw(')'); + } else { + // @deprecated since Twig 3.21 + $compiler + ->write('$this->loadTemplate(') + ->string($this->getAttribute('embedded_template')) + ->raw(', ') + ->repr($this->getTemplateName()) + ->raw(', ') + ->repr($this->getTemplateLine()) + ->raw(', ') + ->string($this->getAttribute('embedded_index')) + ->raw(')'); + } if ($useYield) { $compiler->raw('->unwrap()->yield(');