From: Fabien Potencier Date: Thu, 16 Jun 2011 07:57:17 +0000 (+0200) Subject: added an exception when the template passed to "use" is not a string X-Git-Url: http://git.silmor.de/gitweb/?a=commitdiff_plain;h=47818dd2a1793e9116493f607a785f5cde714f0a;p=konrad%2Ftwig.git added an exception when the template passed to "use" is not a string --- diff --git a/CHANGELOG b/CHANGELOG index c11e0c7..2a41d6a 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -2,6 +2,7 @@ Changes: + * added an exception when the template passed to "use" is not a string * made 'a.b is defined' not throw an exception if a is not defined (in strict mode) * added {% line \d+ %} directive diff --git a/doc/templates.rst b/doc/templates.rst index 3f1ac94..2bda34c 100644 --- a/doc/templates.rst +++ b/doc/templates.rst @@ -1531,6 +1531,11 @@ imported blocks are not outputted automatically): template, if it does not define macros, and if the body is empty. But it can *use* other templates. +.. note:: + + Because ``use`` statements are resolved independently of the context + passed to the template, the template reference cannot be an expression. + The main template can also override any imported block. If the template already defines the ``sidebar`` block, then the one defined in ``blocks.html`` is ignored. To avoid name conflicts, you can rename imported blocks: diff --git a/lib/Twig/TokenParser/Use.php b/lib/Twig/TokenParser/Use.php index 5b8997a..7c1cbee 100644 --- a/lib/Twig/TokenParser/Use.php +++ b/lib/Twig/TokenParser/Use.php @@ -20,6 +20,11 @@ class Twig_TokenParser_Use extends Twig_TokenParser public function parse(Twig_Token $token) { $template = $this->parser->getExpressionParser()->parseExpression(); + + if (!$template instanceof Twig_Node_Expression_Constant) { + throw new Twig_Error_Syntax('The template references in a "use" statement must be a string.', $token->getLine()); + } + $stream = $this->parser->getStream(); $targets = array();