fixed embed compilation when used more than once in a template (closes #714)
authorFabien Potencier <fabien.potencier@gmail.com>
Fri, 27 Apr 2012 07:16:21 +0000 (09:16 +0200)
committerFabien Potencier <fabien.potencier@gmail.com>
Fri, 27 Apr 2012 07:16:28 +0000 (09:16 +0200)
lib/Twig/Node/Module.php
lib/Twig/Parser.php
test/Twig/Tests/Fixtures/tags/embed/multiple.test [new file with mode: 0644]

index 2b8ae2f..4c7a107 100644 (file)
@@ -18,7 +18,7 @@
  */
 class Twig_Node_Module extends Twig_Node
 {
-    public function __construct(Twig_NodeInterface $body, Twig_Node_Expression $parent = null, Twig_NodeInterface $blocks, Twig_NodeInterface $macros, Twig_NodeInterface $traits, Twig_NodeInterface $embeddedTemplates, $filename)
+    public function __construct(Twig_NodeInterface $body, Twig_Node_Expression $parent = null, Twig_NodeInterface $blocks, Twig_NodeInterface $macros, Twig_NodeInterface $traits, $embeddedTemplates, $filename)
     {
         // embedded templates are set as attributes so that they are only visited once by the visitors
         parent::__construct(array('parent' => $parent, 'body' => $body, 'blocks' => $blocks, 'macros' => $macros, 'traits' => $traits), array('filename' => $filename, 'index' => null, 'embedded_templates' => $embeddedTemplates), 1);
index 6e5648c..0bfcec7 100644 (file)
@@ -92,6 +92,7 @@ class Twig_Parser implements Twig_ParserInterface
         $this->traits = array();
         $this->blockStack = array();
         $this->importedFunctions = array(array());
+        $this->embeddedTemplates = array();
 
         try {
             $body = $this->subparse($test, $dropNeedle);
@@ -109,7 +110,7 @@ class Twig_Parser implements Twig_ParserInterface
             throw $e;
         }
 
-        $node = new Twig_Node_Module(new Twig_Node_Body(array($body)), $this->parent, new Twig_Node($this->blocks), new Twig_Node($this->macros), new Twig_Node($this->traits), new Twig_Node($this->embeddedTemplates), $this->stream->getFilename());
+        $node = new Twig_Node_Module(new Twig_Node_Body(array($body)), $this->parent, new Twig_Node($this->blocks), new Twig_Node($this->macros), new Twig_Node($this->traits), $this->embeddedTemplates, $this->stream->getFilename());
 
         $traverser = new Twig_NodeTraverser($this->env, $this->visitors);
 
diff --git a/test/Twig/Tests/Fixtures/tags/embed/multiple.test b/test/Twig/Tests/Fixtures/tags/embed/multiple.test
new file mode 100644 (file)
index 0000000..da161e6
--- /dev/null
@@ -0,0 +1,50 @@
+--TEST--
+"embed" tag
+--TEMPLATE--
+FOO
+{% embed "foo.twig" %}
+    {% block c1 %}
+        {{ parent() }}
+        block1extended
+    {% endblock %}
+{% endembed %}
+
+{% embed "foo.twig" %}
+    {% block c1 %}
+        {{ parent() }}
+        block1extended
+    {% endblock %}
+{% endembed %}
+
+BAR
+--TEMPLATE(foo.twig)--
+A
+{% block c1 %}
+    block1
+{% endblock %}
+B
+{% block c2 %}
+    block2
+{% endblock %}
+C
+--DATA--
+return array()
+--EXPECT--
+FOO
+
+A
+            block1
+
+        block1extended
+    B
+    block2
+C
+
+A
+            block1
+
+        block1extended
+    B
+    block2
+C
+BAR