From: Fabien Potencier Date: Sat, 6 Aug 2011 07:16:03 +0000 (+0200) Subject: removed the possibility to use the extends tag from a block (as it is semantically... X-Git-Url: http://git.silmor.de/gitweb/?a=commitdiff_plain;h=801f3e638c76d57172b07d685c18f47eb1efbb27;p=konrad%2Ftwig.git removed the possibility to use the extends tag from a block (as it is semantically incorrect and it probably does not work as you expect it to in this case) --- diff --git a/CHANGELOG b/CHANGELOG index 81bb39c..401bd1f 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,5 +1,6 @@ * 1.2.0 + * removed the possibility to use the "extends" tag from a block * added "if" modifier support to "for" loops * 1.1.2 (2011-07-30) diff --git a/lib/Twig/Parser.php b/lib/Twig/Parser.php index 057c1e8..d6310e0 100644 --- a/lib/Twig/Parser.php +++ b/lib/Twig/Parser.php @@ -244,6 +244,11 @@ class Twig_Parser implements Twig_ParserInterface } } + public function isMainScope() + { + return 1 === count($this->importedFunctions); + } + public function pushLocalScope() { array_unshift($this->importedFunctions, array()); diff --git a/lib/Twig/TokenParser/Extends.php b/lib/Twig/TokenParser/Extends.php index d9fe698..67eacda 100644 --- a/lib/Twig/TokenParser/Extends.php +++ b/lib/Twig/TokenParser/Extends.php @@ -28,6 +28,10 @@ class Twig_TokenParser_Extends extends Twig_TokenParser */ public function parse(Twig_Token $token) { + if (!$this->parser->isMainScope()) { + throw new Twig_Error_Syntax('Cannot extend from a block', $token->getLine()); + } + if (null !== $this->parser->getParent()) { throw new Twig_Error_Syntax('Multiple extends tags are forbidden', $token->getLine()); }