From 7603ef193b7845a09d1f0bed2b360bdf273495d6 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Tue, 25 May 2010 16:43:30 +0200 Subject: [PATCH] changed the grammar for the short-notation of the block tag to be more consistent with other tags --- CHANGELOG | 4 ++++ doc/02-Twig-for-Template-Designers.markdown | 5 +---- lib/Twig/TokenParser/Block.php | 2 ++ lib/Twig/TokenParser/Debug.php | 8 ++++++++ lib/Twig/TokenParser/Set.php | 2 +- test/fixtures/tags/block/basic.test | 2 +- 6 files changed, 17 insertions(+), 6 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index e9af763..fc1b1fc 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,5 +1,9 @@ * 0.9.7-DEV +Backward incompatibilities: + * The short notation of the `block` tag changed. + + * added a 'as' string to the block tag short notation ({% block title "Title" %} must now be {% block title as "Title" %}) * 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) diff --git a/doc/02-Twig-for-Template-Designers.markdown b/doc/02-Twig-for-Template-Designers.markdown index 946dd6e..f33857d 100644 --- a/doc/02-Twig-for-Template-Designers.markdown +++ b/doc/02-Twig-for-Template-Designers.markdown @@ -296,10 +296,7 @@ following constructs do the same: - [twig] - {% block title page_title|title %} - -Note that as soon as you specify a second argument it's treated as short block -and Twig won't look for a closing tag. + {% block title as page_title|title %} Import Context Behavior ----------------------- diff --git a/lib/Twig/TokenParser/Block.php b/lib/Twig/TokenParser/Block.php index cbad921..5be60ea 100644 --- a/lib/Twig/TokenParser/Block.php +++ b/lib/Twig/TokenParser/Block.php @@ -33,6 +33,8 @@ class Twig_TokenParser_Block extends Twig_TokenParser } } } else { + $stream->expect(Twig_Token::NAME_TYPE, 'as'); + $body = new Twig_NodeList(array( new Twig_Node_Print($this->parser->getExpressionParser()->parseExpression(), $lineno), )); diff --git a/lib/Twig/TokenParser/Debug.php b/lib/Twig/TokenParser/Debug.php index 1ad985f..01fc6e2 100644 --- a/lib/Twig/TokenParser/Debug.php +++ b/lib/Twig/TokenParser/Debug.php @@ -1,5 +1,13 @@ test(Twig_Token::NAME_TYPE, 'as')) { - $stream->expect(Twig_Token::NAME_TYPE, 'as'); + $stream->next(); list(, $values) = $this->parser->getExpressionParser()->parseMultitargetExpression(); $stream->expect(Twig_Token::BLOCK_END_TYPE); diff --git a/test/fixtures/tags/block/basic.test b/test/fixtures/tags/block/basic.test index 360dcf0..ecb7210 100644 --- a/test/fixtures/tags/block/basic.test +++ b/test/fixtures/tags/block/basic.test @@ -2,7 +2,7 @@ "block" tag --TEMPLATE-- {% block title1 %}FOO{% endblock %} -{% block title2 foo|lower %} +{% block title2 as foo|lower %} --TEMPLATE(foo.twig)-- {% block content %}{% endblock %} --DATA-- -- 1.7.2.5