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