* 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
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;
}
}
+ 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);