Fixed inheritance in a 'use'-hierarchy
authorMartin Hasoň <martin.hason@gmail.com>
Mon, 24 Mar 2014 05:05:09 +0000 (06:05 +0100)
committerMartin Hasoň <martin.hason@gmail.com>
Thu, 27 Mar 2014 10:53:33 +0000 (11:53 +0100)
lib/Twig/Template.php
test/Twig/Tests/Fixtures/tags/use/inheritance.test [new file with mode: 0644]
test/Twig/Tests/Fixtures/tags/use/inheritance2.test [new file with mode: 0644]
test/Twig/Tests/Fixtures/tags/use/parent_block.test [new file with mode: 0644]
test/Twig/Tests/Fixtures/tags/use/parent_block2.test [new file with mode: 0644]
test/Twig/Tests/Fixtures/tags/use/parent_block3.test [new file with mode: 0644]

index 1fe203f..2ead6ab 100644 (file)
@@ -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 (file)
index 0000000..6368b08
--- /dev/null
@@ -0,0 +1,25 @@
+--TEST--
+"use" tag
+--TEMPLATE--
+{% use "parent.twig" %}
+
+{{ block('container') }}
+--TEMPLATE(parent.twig)--
+{% use "ancestor.twig" %}
+
+{% block sub_container %}
+    <div class="overriden_sub_container">overriden sub_container</div>
+{% endblock %}
+--TEMPLATE(ancestor.twig)--
+{% block container %}
+    <div class="container">{{ block('sub_container') }}</div>
+{% endblock %}
+
+{% block sub_container %}
+    <div class="sub_container">sub_container</div>
+{% endblock %}
+--DATA--
+return array()
+--EXPECT--
+<div class="container">    <div class="overriden_sub_container">overriden sub_container</div>
+</div>
diff --git a/test/Twig/Tests/Fixtures/tags/use/inheritance2.test b/test/Twig/Tests/Fixtures/tags/use/inheritance2.test
new file mode 100644 (file)
index 0000000..114e301
--- /dev/null
@@ -0,0 +1,24 @@
+--TEST--
+"use" tag
+--TEMPLATE--
+{% use "ancestor.twig" %}
+{% use "parent.twig" %}
+
+{{ block('container') }}
+--TEMPLATE(parent.twig)--
+{% block sub_container %}
+    <div class="overriden_sub_container">overriden sub_container</div>
+{% endblock %}
+--TEMPLATE(ancestor.twig)--
+{% block container %}
+    <div class="container">{{ block('sub_container') }}</div>
+{% endblock %}
+
+{% block sub_container %}
+    <div class="sub_container">sub_container</div>
+{% endblock %}
+--DATA--
+return array()
+--EXPECT--
+<div class="container">    <div class="overriden_sub_container">overriden sub_container</div>
+</div>
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 (file)
index 0000000..59db23d
--- /dev/null
@@ -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 (file)
index 0000000..d3f302d
--- /dev/null
@@ -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 (file)
index 0000000..95b55a4
--- /dev/null
@@ -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)