fixed inheritance
authorFabien Potencier <fabien.potencier@gmail.com>
Tue, 29 Jun 2010 14:28:02 +0000 (16:28 +0200)
committerFabien Potencier <fabien.potencier@gmail.com>
Tue, 29 Jun 2010 14:28:02 +0000 (16:28 +0200)
CHANGELOG
lib/Twig/Node/Module.php
test/Twig/Tests/Fixtures/tags/inheritance/parent_isolation.test [new file with mode: 0644]
test/Twig/Tests/Node/ModuleTest.php
test/Twig/Tests/Node/SandboxedModuleTest.php

index b91e3d7..8410b1b 100644 (file)
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -3,6 +3,7 @@
 Backward incompatibilities:
  * the self special variable has been renamed to _self
 
+ * fixed inheritance
  * added the special _context variable to reference the current context
  * renamed self to _self (to avoid conflict)
  * fixed Twig_Template::getAttribute() for protected properties
index 2f4f97d..7ffa28c 100644 (file)
@@ -72,7 +72,7 @@ class Twig_Node_Module extends Twig_Node
 
             if ($this->parent instanceof Twig_Node_Expression_Constant) {
                 $compiler
-                    ->write("\$this->parent = \$this->env->loadTemplate(")
+                    ->write("\$this->parent = clone \$this->env->loadTemplate(")
                     ->subcompile($this->parent)
                     ->raw(");\n")
                 ;
@@ -84,7 +84,7 @@ class Twig_Node_Module extends Twig_Node
                     ->write("if (!\$this->parent")
                     ->raw(" instanceof Twig_Template) {\n")
                     ->indent()
-                    ->write("\$this->parent = \$this->env->loadTemplate(\$this->parent);\n")
+                    ->write("\$this->parent = clone \$this->env->loadTemplate(\$this->parent);\n")
                     ->outdent()
                     ->write("}\n")
                 ;
diff --git a/test/Twig/Tests/Fixtures/tags/inheritance/parent_isolation.test b/test/Twig/Tests/Fixtures/tags/inheritance/parent_isolation.test
new file mode 100644 (file)
index 0000000..4cfa895
--- /dev/null
@@ -0,0 +1,16 @@
+--TEST--
+"extends" tag
+--TEMPLATE--
+{% extends "base.twig" %}
+{% block content %}{% include "included.twig" %}{% endblock %}
+{% block footer %}Footer{% endblock %}
+--TEMPLATE(included.twig)--
+{% extends "base.twig" %}
+{% block content %}{% endblock %}
+--TEMPLATE(base.twig)--
+{% block content %}{% endblock %}
+{% block footer %}{% endblock %}
+--DATA--
+return array()
+--EXPECT--
+Footer
index 261c05b..be6d8d8 100644 (file)
@@ -94,7 +94,7 @@ class __TwigTemplate_be925a7b06dda0dfdbd18a1509f7eb34 extends Twig_Template
     {
         \$context['macro'] = \$this->env->loadTemplate("foo.twig", true);
         if (null === \$this->parent) {
-            \$this->parent = \$this->env->loadTemplate("layout.twig");
+            \$this->parent = clone \$this->env->loadTemplate("layout.twig");
             \$this->parent->pushBlocks(\$this->blocks);
         }
         \$this->parent->display(\$context);
@@ -126,7 +126,7 @@ class __TwigTemplate_be925a7b06dda0dfdbd18a1509f7eb34 extends Twig_Template
         if (null === \$this->parent) {
             \$this->parent = (true) ? ("foo") : ("foo");
             if (!\$this->parent instanceof Twig_Template) {
-                \$this->parent = \$this->env->loadTemplate(\$this->parent);
+                \$this->parent = clone \$this->env->loadTemplate(\$this->parent);
             }
             \$this->parent->pushBlocks(\$this->blocks);
         }
index 2769aa9..e823741 100644 (file)
@@ -102,7 +102,7 @@ class __TwigTemplate_be925a7b06dda0dfdbd18a1509f7eb34 extends Twig_Template
     public function display(array \$context)
     {
         if (null === \$this->parent) {
-            \$this->parent = \$this->env->loadTemplate("layout.twig");
+            \$this->parent = clone \$this->env->loadTemplate("layout.twig");
             \$this->parent->pushBlocks(\$this->blocks);
         }
         \$this->parent->display(\$context);