|
19 | 19 | use Twig\Node\Expression\AbstractExpression;
|
20 | 20 | use Twig\Node\Node;
|
21 | 21 | use Twig\Node\NodeOutputInterface;
|
| 22 | +use Twig\Template; |
22 | 23 |
|
23 | 24 | /**
|
24 | 25 | * @author Fabien Potencier <[email protected]>
|
@@ -48,7 +49,7 @@ public function compile(Compiler $compiler): void
|
48 | 49 | {
|
49 | 50 | $compiler->addDebugInfo($this);
|
50 | 51 |
|
51 |
| - $useYield = method_exists(Environment::class, 'useYield') && $compiler->getEnvironment()->useYield(); |
| 52 | + $useYield = $compiler->getEnvironment()->useYield(); |
52 | 53 |
|
53 | 54 | // since twig/twig 3.9.0: Using the internal "twig_to_array" function is deprecated.
|
54 | 55 | if (method_exists(CoreExtension::class, 'toArray')) {
|
@@ -154,17 +155,29 @@ public function compile(Compiler $compiler): void
|
154 | 155 | if ($useYield) {
|
155 | 156 | $compiler->write('yield from ');
|
156 | 157 | }
|
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(')'); |
167 | 158 |
|
| 159 | + if (method_exists(Template::class, 'load')) { |
| 160 | + $compiler |
| 161 | + ->write('$this->load(') |
| 162 | + ->string($this->getAttribute('embedded_template')) |
| 163 | + ->raw(', ') |
| 164 | + ->raw($this->getTemplateLine()) |
| 165 | + ->raw(', ') |
| 166 | + ->string($this->getAttribute('embedded_index')) |
| 167 | + ->raw(')'); |
| 168 | + } else { |
| 169 | + // Environment::loadTemplate is 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 | + } |
168 | 181 | if ($useYield) {
|
169 | 182 | $compiler->raw('->unwrap()->yield(');
|
170 | 183 | } else {
|
|
0 commit comments