From b7ca23f8be7dcce6b172a7ad1d67f361d796ca9b Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Tue, 26 Jun 2012 17:59:41 +0200 Subject: [PATCH] fixed nested embed tag calls --- CHANGELOG | 2 +- lib/Twig/Parser.php | 2 +- test/Twig/Tests/Fixtures/tags/embed/nested.test | 42 +++++++++++++++++++++++ 3 files changed, 44 insertions(+), 2 deletions(-) create mode 100644 test/Twig/Tests/Fixtures/tags/embed/nested.test diff --git a/CHANGELOG b/CHANGELOG index 862454d..40ee1e5 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,6 +1,6 @@ * 1.8.4 (2012-XX-XX) - * n/a + * fixed nested embed tag calls * 1.8.3 (2012-06-17) diff --git a/lib/Twig/Parser.php b/lib/Twig/Parser.php index 8c578fd..771a7bd 100644 --- a/lib/Twig/Parser.php +++ b/lib/Twig/Parser.php @@ -275,7 +275,7 @@ class Twig_Parser implements Twig_ParserInterface public function embedTemplate(Twig_Node_Module $template) { - $template->setIndex(count($this->embeddedTemplates) + 1); + $template->setIndex(mt_rand()); $this->embeddedTemplates[] = $template; } diff --git a/test/Twig/Tests/Fixtures/tags/embed/nested.test b/test/Twig/Tests/Fixtures/tags/embed/nested.test new file mode 100644 index 0000000..81563dc --- /dev/null +++ b/test/Twig/Tests/Fixtures/tags/embed/nested.test @@ -0,0 +1,42 @@ +--TEST-- +"embed" tag +--TEMPLATE-- +{% embed "foo.twig" %} + {% block c1 %} + {{ parent() }} + {% embed "foo.twig" %} + {% block c1 %} + {{ parent() }} + block1extended + {% endblock %} + {% endembed %} + + {% endblock %} +{% endembed %} +--TEMPLATE(foo.twig)-- +A +{% block c1 %} + block1 +{% endblock %} +B +{% block c2 %} + block2 +{% endblock %} +C +--DATA-- +return array() +--EXPECT-- +A + block1 + + +A + block1 + + block1extended + B + block2 +C + B + block2 +C -- 1.7.2.5