From: Fabien Potencier Date: Fri, 11 Jun 2010 10:10:32 +0000 (+0200) Subject: fixed a bug when a template with a layout is reused more than one time X-Git-Url: http://git.silmor.de/gitweb/?a=commitdiff_plain;h=c017a93e7770b60e235a9f15b8639dcad086d74c;p=web%2Fkonrad%2Ftwig.git fixed a bug when a template with a layout is reused more than one time --- diff --git a/lib/Twig/Node/Module.php b/lib/Twig/Node/Module.php index ed98ac6..eeaddc8 100644 --- a/lib/Twig/Node/Module.php +++ b/lib/Twig/Node/Module.php @@ -61,6 +61,11 @@ class Twig_Node_Module extends Twig_Node } } + $compiler + ->write("if (null === \$this->parent) {\n") + ->indent(); + ; + if ($this->parent instanceof Twig_Node_Expression_Constant) { $compiler ->write("\$this->parent = \$this->env->loadTemplate(") @@ -83,6 +88,8 @@ class Twig_Node_Module extends Twig_Node $compiler ->write("\$this->parent->pushBlocks(\$this->blocks);\n") + ->outdent() + ->write("}\n") ->write("\$this->parent->display(\$context);\n") ; } else { diff --git a/test/Twig/Tests/Node/ModuleTest.php b/test/Twig/Tests/Node/ModuleTest.php index 837a298..2e78f2e 100644 --- a/test/Twig/Tests/Node/ModuleTest.php +++ b/test/Twig/Tests/Node/ModuleTest.php @@ -103,8 +103,10 @@ class __TwigTemplate_be925a7b06dda0dfdbd18a1509f7eb34 extends Twig_Template public function display(array \$context) { \$context['macro'] = \$this->env->loadTemplate("foo.twig", true); - \$this->parent = \$this->env->loadTemplate("layout.twig"); - \$this->parent->pushBlocks(\$this->blocks); + if (null === \$this->parent) { + \$this->parent = \$this->env->loadTemplate("layout.twig"); + \$this->parent->pushBlocks(\$this->blocks); + } \$this->parent->display(\$context); } @@ -140,11 +142,13 @@ class __TwigTemplate_be925a7b06dda0dfdbd18a1509f7eb34 extends Twig_Template public function display(array \$context) { - \$this->parent = (true) ? ("foo") : ("foo"); - if (!\$this->parent instanceof Twig_Template) { - \$this->parent = \$this->env->loadTemplate(\$this->parent); + if (null === \$this->parent) { + \$this->parent = (true) ? ("foo") : ("foo"); + if (!\$this->parent instanceof Twig_Template) { + \$this->parent = \$this->env->loadTemplate(\$this->parent); + } + \$this->parent->pushBlocks(\$this->blocks); } - \$this->parent->pushBlocks(\$this->blocks); \$this->parent->display(\$context); } diff --git a/test/Twig/Tests/Node/SandboxedModuleTest.php b/test/Twig/Tests/Node/SandboxedModuleTest.php index ac476db..4e2cd0b 100644 --- a/test/Twig/Tests/Node/SandboxedModuleTest.php +++ b/test/Twig/Tests/Node/SandboxedModuleTest.php @@ -110,8 +110,10 @@ class __TwigTemplate_be925a7b06dda0dfdbd18a1509f7eb34 extends Twig_Template public function display(array \$context) { - \$this->parent = \$this->env->loadTemplate("layout.twig"); - \$this->parent->pushBlocks(\$this->blocks); + if (null === \$this->parent) { + \$this->parent = \$this->env->loadTemplate("layout.twig"); + \$this->parent->pushBlocks(\$this->blocks); + } \$this->parent->display(\$context); }