From: Fabien Potencier Date: Thu, 2 Dec 2010 15:13:54 +0000 (+0100) Subject: added a syntax error exception when parent block is used on a template that does... X-Git-Url: http://git.silmor.de/gitweb/?a=commitdiff_plain;h=08bd27f7720c262069d278cf84994839a7769af8;p=web%2Fkonrad%2Ftwig.git added a syntax error exception when parent block is used on a template that does not extend another one --- diff --git a/CHANGELOG b/CHANGELOG index f493b4b..8ce0ffd 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,5 +1,6 @@ * 0.9.10 + * added a syntax error exception when parent block is used on a template that does not extend another one * made the Escaper and Optimizer extensions enabled by default * fixed sandbox extension when used with auto output escaping * fixed escaper when wrapping a Twig_Node_Print (the original class must be preserved) diff --git a/lib/Twig/TokenParser/Parent.php b/lib/Twig/TokenParser/Parent.php index d9204e6..afde369 100644 --- a/lib/Twig/TokenParser/Parent.php +++ b/lib/Twig/TokenParser/Parent.php @@ -25,6 +25,10 @@ class Twig_TokenParser_Parent extends Twig_TokenParser } $this->parser->getStream()->expect(Twig_Token::BLOCK_END_TYPE); + if (!$this->parser->getParent()) { + throw new Twig_Error_Syntax('Calling "parent" on a template that does not extend another one is forbidden', $token->getLine()); + } + return new Twig_Node_Parent($this->parser->peekBlockStack(), $token->getLine(), $this->getTag()); }