From: Fabien Potencier Date: Fri, 27 Apr 2012 07:16:21 +0000 (+0200) Subject: fixed embed compilation when used more than once in a template (closes #714) X-Git-Url: http://git.silmor.de/gitweb/?a=commitdiff_plain;h=635bafd46e4f437ae7a215991f5f09839917f9e5;p=web%2Fkonrad%2Ftwig.git fixed embed compilation when used more than once in a template (closes #714) --- diff --git a/lib/Twig/Node/Module.php b/lib/Twig/Node/Module.php index 2b8ae2f..4c7a107 100644 --- a/lib/Twig/Node/Module.php +++ b/lib/Twig/Node/Module.php @@ -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); diff --git a/lib/Twig/Parser.php b/lib/Twig/Parser.php index 6e5648c..0bfcec7 100644 --- a/lib/Twig/Parser.php +++ b/lib/Twig/Parser.php @@ -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 index 0000000..da161e6 --- /dev/null +++ b/test/Twig/Tests/Fixtures/tags/embed/multiple.test @@ -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