mirror of
https://github.com/twigphp/Twig.git
synced 2026-08-31 04:27:00 +00:00
Add support for templates that do not have output Nodes
This commit is contained in:
@@ -342,6 +342,9 @@ final class ModuleNode extends Node
|
||||
} else {
|
||||
$compiler->raw("->display(\$context, array_merge(\$this->blocks, \$blocks));\n");
|
||||
}
|
||||
} elseif ($compiler->getEnvironment()->useYield() && !$this->hasNodeOutputNodes($this->getNode('body'))) {
|
||||
// ensure at least one yield call even for templates with no output
|
||||
$compiler->write("yield;\n");
|
||||
}
|
||||
|
||||
$compiler
|
||||
@@ -483,4 +486,19 @@ final class ModuleNode extends Node
|
||||
throw new \LogicException('Trait templates can only be constant nodes.');
|
||||
}
|
||||
}
|
||||
|
||||
private function hasNodeOutputNodes(Node $node): bool
|
||||
{
|
||||
if ($node instanceof NodeOutputInterface) {
|
||||
return true;
|
||||
}
|
||||
|
||||
foreach ($node as $child) {
|
||||
if ($this->hasNodeOutputNodes($child)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user