Browse code

fixed a regression when a template only extends another one without defining any blocks

Fabien Potencier authored on 03/04/2012 17:12:14
Showing 5 changed files
... ...
@@ -1,3 +1,7 @@
1
+* 1.6.5 (2012-04-11)
2
+
3
+ * fixed a regression when a template only extends another one without defining any blocks
4
+
1 5
 * 1.6.4 (2012-04-02)
2 6
 
3 7
  * fixed PHP notice in Twig_Error::guessTemplateLine() introduced in 1.6.3
... ...
@@ -37,7 +37,7 @@ class Twig_Node_Module extends Twig_Node
37 37
     {
38 38
         $this->compileClassHeader($compiler);
39 39
 
40
-        if (count($this->getNode('blocks')) || count($this->getNode('traits'))) {
40
+        if (count($this->getNode('blocks')) || count($this->getNode('traits')) || null === $this->getNode('parent') || $this->getNode('parent') instanceof Twig_Node_Expression_Constant) {
41 41
             $this->compileConstructor($compiler);
42 42
         }
43 43
 
44 44
new file mode 100644
... ...
@@ -0,0 +1,10 @@
1
+--TEST--
2
+"extends" tag
3
+--TEMPLATE--
4
+{% extends "foo.twig" %}
5
+--TEMPLATE(foo.twig)--
6
+{% block content %}FOO{% endblock %}
7
+--DATA--
8
+return array()
9
+--EXPECT--
10
+FOO
... ...
@@ -69,6 +69,16 @@ class Twig_Tests_Node_ModuleTest extends Twig_Tests_Node_TestCase
69 69
 /* foo.twig */
70 70
 class __TwigTemplate_be925a7b06dda0dfdbd18a1509f7eb34 extends Twig_Template
71 71
 {
72
+    public function __construct(Twig_Environment \$env)
73
+    {
74
+        parent::__construct(\$env);
75
+
76
+        \$this->parent = false;
77
+
78
+        \$this->blocks = array(
79
+        );
80
+    }
81
+
72 82
     protected function doDisplay(array \$context, array \$blocks = array())
73 83
     {
74 84
         echo "foo";
... ...
@@ -99,6 +109,16 @@ EOF
99 109
 /* foo.twig */
100 110
 class __TwigTemplate_be925a7b06dda0dfdbd18a1509f7eb34 extends Twig_Template
101 111
 {
112
+    public function __construct(Twig_Environment \$env)
113
+    {
114
+        parent::__construct(\$env);
115
+
116
+        \$this->parent = \$this->env->loadTemplate("layout.twig");
117
+
118
+        \$this->blocks = array(
119
+        );
120
+    }
121
+
102 122
     protected function doGetParent(array \$context)
103 123
     {
104 124
         return "layout.twig";
... ...
@@ -67,6 +67,16 @@ class Twig_Tests_Node_SandboxedModuleTest extends Twig_Tests_Node_TestCase
67 67
 /* foo.twig */
68 68
 class __TwigTemplate_be925a7b06dda0dfdbd18a1509f7eb34 extends Twig_Template
69 69
 {
70
+    public function __construct(Twig_Environment \$env)
71
+    {
72
+        parent::__construct(\$env);
73
+
74
+        \$this->parent = false;
75
+
76
+        \$this->blocks = array(
77
+        );
78
+    }
79
+
70 80
     protected function doDisplay(array \$context, array \$blocks = array())
71 81
     {
72 82
         \$this->checkSecurity();
... ...
@@ -110,6 +120,16 @@ EOF
110 120
 /* foo.twig */
111 121
 class __TwigTemplate_be925a7b06dda0dfdbd18a1509f7eb34 extends Twig_Template
112 122
 {
123
+    public function __construct(Twig_Environment \$env)
124
+    {
125
+        parent::__construct(\$env);
126
+
127
+        \$this->parent = \$this->env->loadTemplate("layout.twig");
128
+
129
+        \$this->blocks = array(
130
+        );
131
+    }
132
+
113 133
     protected function doGetParent(array \$context)
114 134
     {
115 135
         return "layout.twig";