From 9e0907e19a53fb16a9b31bfb704437c88f7d2ca9 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Martin=20Haso=C5=88?= Date: Mon, 24 Mar 2014 06:05:09 +0100 Subject: [PATCH] Fixed inheritance in a 'use'-hierarchy --- lib/Twig/Template.php | 2 +- test/Twig/Tests/Fixtures/tags/use/inheritance.test | 25 +++++++++++++ .../Twig/Tests/Fixtures/tags/use/inheritance2.test | 24 ++++++++++++ .../Twig/Tests/Fixtures/tags/use/parent_block.test | 24 ++++++++++++ .../Tests/Fixtures/tags/use/parent_block2.test | 24 ++++++++++++ .../Tests/Fixtures/tags/use/parent_block3.test | 38 ++++++++++++++++++++ 6 files changed, 136 insertions(+), 1 deletions(-) create mode 100644 test/Twig/Tests/Fixtures/tags/use/inheritance.test create mode 100644 test/Twig/Tests/Fixtures/tags/use/inheritance2.test create mode 100644 test/Twig/Tests/Fixtures/tags/use/parent_block.test create mode 100644 test/Twig/Tests/Fixtures/tags/use/parent_block2.test create mode 100644 test/Twig/Tests/Fixtures/tags/use/parent_block3.test diff --git a/lib/Twig/Template.php b/lib/Twig/Template.php index 1fe203f..2ead6ab 100644 --- a/lib/Twig/Template.php +++ b/lib/Twig/Template.php @@ -250,7 +250,7 @@ abstract class Twig_Template implements Twig_TemplateInterface */ public function display(array $context, array $blocks = array()) { - $this->displayWithErrorHandling($this->env->mergeGlobals($context), $blocks); + $this->displayWithErrorHandling($this->env->mergeGlobals($context), array_merge($this->blocks, $blocks)); } /** diff --git a/test/Twig/Tests/Fixtures/tags/use/inheritance.test b/test/Twig/Tests/Fixtures/tags/use/inheritance.test new file mode 100644 index 0000000..6368b08 --- /dev/null +++ b/test/Twig/Tests/Fixtures/tags/use/inheritance.test @@ -0,0 +1,25 @@ +--TEST-- +"use" tag +--TEMPLATE-- +{% use "parent.twig" %} + +{{ block('container') }} +--TEMPLATE(parent.twig)-- +{% use "ancestor.twig" %} + +{% block sub_container %} +
overriden sub_container
+{% endblock %} +--TEMPLATE(ancestor.twig)-- +{% block container %} +
{{ block('sub_container') }}
+{% endblock %} + +{% block sub_container %} +
sub_container
+{% endblock %} +--DATA-- +return array() +--EXPECT-- +
overriden sub_container
+
diff --git a/test/Twig/Tests/Fixtures/tags/use/inheritance2.test b/test/Twig/Tests/Fixtures/tags/use/inheritance2.test new file mode 100644 index 0000000..114e301 --- /dev/null +++ b/test/Twig/Tests/Fixtures/tags/use/inheritance2.test @@ -0,0 +1,24 @@ +--TEST-- +"use" tag +--TEMPLATE-- +{% use "ancestor.twig" %} +{% use "parent.twig" %} + +{{ block('container') }} +--TEMPLATE(parent.twig)-- +{% block sub_container %} +
overriden sub_container
+{% endblock %} +--TEMPLATE(ancestor.twig)-- +{% block container %} +
{{ block('sub_container') }}
+{% endblock %} + +{% block sub_container %} +
sub_container
+{% endblock %} +--DATA-- +return array() +--EXPECT-- +
overriden sub_container
+
diff --git a/test/Twig/Tests/Fixtures/tags/use/parent_block.test b/test/Twig/Tests/Fixtures/tags/use/parent_block.test new file mode 100644 index 0000000..59db23d --- /dev/null +++ b/test/Twig/Tests/Fixtures/tags/use/parent_block.test @@ -0,0 +1,24 @@ +--TEST-- +"use" tag +--TEMPLATE-- +{% use 'file2.html.twig' with foobar as base_base_foobar %} +{% block foobar %} + {{- block('base_base_foobar') -}} + Content of block (second override) +{% endblock foobar %} +--TEMPLATE(file2.html.twig)-- +{% use 'file1.html.twig' with foobar as base_foobar %} +{% block foobar %} + {{- block('base_foobar') -}} + Content of block (first override) +{% endblock foobar %} +--TEMPLATE(file1.html.twig)-- +{% block foobar -%} + Content of block +{% endblock foobar %} +--DATA-- +return array() +--EXPECT-- +Content of block +Content of block (first override) +Content of block (second override) diff --git a/test/Twig/Tests/Fixtures/tags/use/parent_block2.test b/test/Twig/Tests/Fixtures/tags/use/parent_block2.test new file mode 100644 index 0000000..d3f302d --- /dev/null +++ b/test/Twig/Tests/Fixtures/tags/use/parent_block2.test @@ -0,0 +1,24 @@ +--TEST-- +"use" tag +--TEMPLATE-- +{% use 'file2.html.twig'%} +{% block foobar %} + {{- parent() -}} + Content of block (second override) +{% endblock foobar %} +--TEMPLATE(file2.html.twig)-- +{% use 'file1.html.twig' %} +{% block foobar %} + {{- parent() -}} + Content of block (first override) +{% endblock foobar %} +--TEMPLATE(file1.html.twig)-- +{% block foobar -%} + Content of block +{% endblock foobar %} +--DATA-- +return array() +--EXPECT-- +Content of block +Content of block (first override) +Content of block (second override) diff --git a/test/Twig/Tests/Fixtures/tags/use/parent_block3.test b/test/Twig/Tests/Fixtures/tags/use/parent_block3.test new file mode 100644 index 0000000..95b55a4 --- /dev/null +++ b/test/Twig/Tests/Fixtures/tags/use/parent_block3.test @@ -0,0 +1,38 @@ +--TEST-- +"use" tag +--TEMPLATE-- +{% use 'file2.html.twig' %} +{% use 'file1.html.twig' with foo %} +{% block foo %} + {{- parent() -}} + Content of foo (second override) +{% endblock foo %} +{% block bar %} + {{- parent() -}} + Content of bar (second override) +{% endblock bar %} +--TEMPLATE(file2.html.twig)-- +{% use 'file1.html.twig' %} +{% block foo %} + {{- parent() -}} + Content of foo (first override) +{% endblock foo %} +{% block bar %} + {{- parent() -}} + Content of bar (first override) +{% endblock bar %} +--TEMPLATE(file1.html.twig)-- +{% block foo -%} + Content of foo +{% endblock foo %} +{% block bar -%} + Content of bar +{% endblock bar %} +--DATA-- +return array() +--EXPECT-- +Content of foo +Content of foo (first override) +Content of foo (second override) +Content of bar +Content of bar (second override) -- 1.7.2.5