mirror of
https://github.com/twigphp/Twig.git
synced 2026-09-14 11:27:00 +00:00
added an exception when a child template has a non-empty body (as it is always ignored when rendering)
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
* 0.9.7-DEV
|
||||
|
||||
* added an exception when a child template has a non-empty body (as it is always ignored when rendering)
|
||||
|
||||
* 0.9.6 (2010-05-12)
|
||||
|
||||
* fixed variables defined outside a loop and for which the value changes in a for loop
|
||||
|
||||
@@ -42,7 +42,14 @@ class Twig_Node_Module extends Twig_Node implements Twig_NodeListInterface
|
||||
|
||||
public function __toString()
|
||||
{
|
||||
$repr = array(get_class($this).'(', ' body:');
|
||||
$repr = array(get_class($this).'(');
|
||||
|
||||
if ($this->extends)
|
||||
{
|
||||
$repr[] = ' extends: '.$this->extends;
|
||||
}
|
||||
|
||||
$repr[] = ' body:';
|
||||
foreach ($this->body->getNodes() as $node) {
|
||||
foreach (explode("\n", $node->__toString()) as $line) {
|
||||
$repr[] = ' '.$line;
|
||||
|
||||
@@ -79,6 +79,21 @@ class Twig_Parser
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->extends)
|
||||
{
|
||||
// check that the body only contains block references and empty text nodes
|
||||
foreach ($body->getNodes() as $node)
|
||||
{
|
||||
if (
|
||||
($node instanceof Twig_Node_Text && !preg_match('/^\s*$/s', $node->getData()))
|
||||
||
|
||||
(!$node instanceof Twig_Node_Text && !$node instanceof Twig_Node_BlockReference)
|
||||
) {
|
||||
throw new Twig_SyntaxError('A template that extends another one cannot have a body', 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$node = new Twig_Node_Module($body, $this->extends, $this->blocks, $this->macros, $this->stream->getFilename());
|
||||
|
||||
$t = new Twig_NodeTraverser($this->env);
|
||||
|
||||
Reference in New Issue
Block a user