mirror of
https://github.com/twigphp/Twig.git
synced 2026-09-01 21:17:21 +00:00
Fix blocks not available under some circumstancies
This commit is contained in:
@@ -40,7 +40,7 @@ class CacheNode extends AbstractExpression
|
||||
->addDebugInfo($this)
|
||||
->raw('$this->env->getRuntime(\'Twig\Extra\Cache\CacheRuntime\')->getCache()->get(')
|
||||
->subcompile($this->getNode('key'))
|
||||
->raw(", function (\Symfony\Contracts\Cache\ItemInterface \$item) use (\$context, \$macros) {\n")
|
||||
->raw(", function (\Symfony\Contracts\Cache\ItemInterface \$item) use (\$context, \$macros, \$blocks) {\n")
|
||||
->indent()
|
||||
;
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ class CaptureNode extends Node
|
||||
{
|
||||
public function __construct(Node $body, int $lineno, ?string $tag = null)
|
||||
{
|
||||
parent::__construct(['body' => $body], ['raw' => false, 'with_blocks' => false], $lineno, $tag);
|
||||
parent::__construct(['body' => $body], ['raw' => false], $lineno, $tag);
|
||||
}
|
||||
|
||||
public function compile(Compiler $compiler): void
|
||||
@@ -34,13 +34,9 @@ class CaptureNode extends Node
|
||||
if (!$this->getAttribute('raw')) {
|
||||
$compiler->raw("('' === \$tmp = ");
|
||||
}
|
||||
$compiler->raw($useYield ? "implode('', iterator_to_array(" : '\\Twig\\Extension\\CoreExtension::captureOutput(');
|
||||
if ($this->getAttribute('with_blocks')) {
|
||||
$compiler->raw("(function () use (&\$context, \$macros, \$blocks) {\n");
|
||||
} else {
|
||||
$compiler->raw("(function () use (&\$context, \$macros) {\n");
|
||||
}
|
||||
$compiler
|
||||
->raw($useYield ? "implode('', iterator_to_array(" : '\\Twig\\Extension\\CoreExtension::captureOutput(')
|
||||
->raw("(function () use (&\$context, \$macros, \$blocks) {\n")
|
||||
->indent()
|
||||
->subcompile($this->getNode('body'))
|
||||
->write("return; yield '';\n")
|
||||
|
||||
@@ -80,7 +80,6 @@ class MacroNode extends Node
|
||||
}
|
||||
|
||||
$node = new CaptureNode($this->getNode('body'), $this->getNode('body')->lineno, $this->getNode('body')->tag);
|
||||
$node->setAttribute('with_blocks', true);
|
||||
|
||||
$compiler
|
||||
->write('')
|
||||
|
||||
@@ -38,7 +38,6 @@ class SetNode extends Node implements NodeCaptureInterface
|
||||
$capture = false;
|
||||
} else {
|
||||
$values = new CaptureNode($values, $values->getTemplateLine());
|
||||
$values->setAttribute('with_blocks', true);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user