fixed nested embed tag calls
authorFabien Potencier <fabien.potencier@gmail.com>
Tue, 26 Jun 2012 15:59:41 +0000 (17:59 +0200)
committerFabien Potencier <fabien.potencier@gmail.com>
Tue, 26 Jun 2012 16:15:55 +0000 (18:15 +0200)
CHANGELOG
lib/Twig/Parser.php
test/Twig/Tests/Fixtures/tags/embed/nested.test [new file with mode: 0644]

index 862454d..40ee1e5 100644 (file)
--- 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)
 
index 8c578fd..771a7bd 100644 (file)
@@ -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 (file)
index 0000000..81563dc
--- /dev/null
@@ -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