fixed template cloning problem with inheritance
authorFabien Potencier <fabien.potencier@gmail.com>
Mon, 12 Jul 2010 15:48:10 +0000 (17:48 +0200)
committerFabien Potencier <fabien.potencier@gmail.com>
Mon, 12 Jul 2010 15:48:10 +0000 (17:48 +0200)
lib/Twig/Node/Module.php
test/Twig/Tests/Node/ModuleTest.php

index 7ffa28c..add0e31 100644 (file)
@@ -78,15 +78,16 @@ class Twig_Node_Module extends Twig_Node
                 ;
             } else {
                 $compiler
-                    ->write("\$this->parent = ")
+                    ->write("\$parent = ")
                     ->subcompile($this->parent)
                     ->raw(";\n")
-                    ->write("if (!\$this->parent")
+                    ->write("if (!\$parent")
                     ->raw(" instanceof Twig_Template) {\n")
                     ->indent()
-                    ->write("\$this->parent = clone \$this->env->loadTemplate(\$this->parent);\n")
+                    ->write("\$parent = \$this->env->loadTemplate(\$parent);\n")
                     ->outdent()
                     ->write("}\n")
+                    ->write("\$this->parent = clone \$parent;\n")
                 ;
             }
 
index be6d8d8..37a891e 100644 (file)
@@ -124,10 +124,11 @@ class __TwigTemplate_be925a7b06dda0dfdbd18a1509f7eb34 extends Twig_Template
     public function display(array \$context)
     {
         if (null === \$this->parent) {
-            \$this->parent = (true) ? ("foo") : ("foo");
-            if (!\$this->parent instanceof Twig_Template) {
-                \$this->parent = clone \$this->env->loadTemplate(\$this->parent);
+            \$parent = (true) ? ("foo") : ("foo");
+            if (!\$parent instanceof Twig_Template) {
+                \$parent = \$this->env->loadTemplate(\$parent);
             }
+            \$this->parent = clone \$parent;
             \$this->parent->pushBlocks(\$this->blocks);
         }
         \$this->parent->display(\$context);