Skip to content

Commit 3ed77b2

Browse files
smnandreKocal
authored andcommitted
[TwigComponent] Fix loadTemplate deprecation for Twig >= 3.21
Fix #2710 cf twigphp/Twig#4583
1 parent 01fcd17 commit 3ed77b2

File tree

1 file changed

+24
-10
lines changed

1 file changed

+24
-10
lines changed

src/TwigComponent/src/Twig/ComponentNode.php

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
use Twig\Node\Expression\AbstractExpression;
2020
use Twig\Node\Node;
2121
use Twig\Node\NodeOutputInterface;
22+
use Twig\Template;
2223

2324
/**
2425
* @author Fabien Potencier <[email protected]>
@@ -154,16 +155,29 @@ public function compile(Compiler $compiler): void
154155
if ($useYield) {
155156
$compiler->write('yield from ');
156157
}
157-
$compiler
158-
->write('$this->loadTemplate(')
159-
->string($this->getAttribute('embedded_template'))
160-
->raw(', ')
161-
->repr($this->getTemplateName())
162-
->raw(', ')
163-
->repr($this->getTemplateLine())
164-
->raw(', ')
165-
->string($this->getAttribute('embedded_index'))
166-
->raw(')');
158+
159+
if (method_exists(Template::class, 'load')) {
160+
$compiler
161+
->write('$this->load(')
162+
->string($this->getAttribute('embedded_template'))
163+
->raw(', ')
164+
->repr($this->getTemplateLine())
165+
->raw(', ')
166+
->string($this->getAttribute('embedded_index'))
167+
->raw(')');
168+
} else {
169+
// @deprecated since Twig 3.21
170+
$compiler
171+
->write('$this->loadTemplate(')
172+
->string($this->getAttribute('embedded_template'))
173+
->raw(', ')
174+
->repr($this->getTemplateName())
175+
->raw(', ')
176+
->repr($this->getTemplateLine())
177+
->raw(', ')
178+
->string($this->getAttribute('embedded_index'))
179+
->raw(')');
180+
}
167181

168182
if ($useYield) {
169183
$compiler->raw('->unwrap()->yield(');

0 commit comments

Comments
 (0)