Skip to content

Commit 0839eea

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

File tree

1 file changed

+23
-10
lines changed

1 file changed

+23
-10
lines changed

src/TwigComponent/src/Twig/ComponentNode.php

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -154,16 +154,29 @@ public function compile(Compiler $compiler): void
154154
if ($useYield) {
155155
$compiler->write('yield from ');
156156
}
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(')');
157+
158+
if (Environment::VERSION_ID >= 32100) {
159+
$compiler
160+
->write('$this->load(')
161+
->string($this->getAttribute('embedded_template'))
162+
->raw(', ')
163+
->repr($this->getTemplateLine())
164+
->raw(', ')
165+
->string($this->getAttribute('embedded_index'))
166+
->raw(')');
167+
} else {
168+
// @deprecated since Twig 3.21
169+
$compiler
170+
->write('$this->loadTemplate(')
171+
->string($this->getAttribute('embedded_template'))
172+
->raw(', ')
173+
->repr($this->getTemplateName())
174+
->raw(', ')
175+
->repr($this->getTemplateLine())
176+
->raw(', ')
177+
->string($this->getAttribute('embedded_index'))
178+
->raw(')');
179+
}
167180

168181
if ($useYield) {
169182
$compiler->raw('->unwrap()->yield(');

0 commit comments

Comments
 (0)