added support for an array of templates to the "extends" tag

This commit is contained in:
Fabien Potencier
2011-08-27 14:33:01 +02:00
parent c56dd32f57
commit 4402ee2c1d
5 changed files with 33 additions and 3 deletions
+1 -1
View File
@@ -1,7 +1,7 @@
* 1.2.0
* added a way to ignore a missing template when using the "include" tag ({% include "foo" ignore missing %})
* added support for an array of templates to the "include" tag ({% include ['foo', 'bar'] %})
* added support for an array of templates to the "include" and "extends" tags ({% include ['foo', 'bar'] %})
* added support for bitwise operators in expressions
* added the "attribute" function to allow getting dynamic attributes on variables
* added Twig_Loader_Chain
+10
View File
@@ -401,6 +401,16 @@ the parent template::
$twig->display('template.twig', array('layout' => $layout));
.. versionadded:: 1.2
The possibility to pass an array of templates has been added in Twig 1.2.
You can also provide a list of templates that are checked for existence. The
first template that exists will be used as a parent::
.. code-block:: jinja
{% extends ['layout.html', 'base_layout.html'] %}
Conditional Inheritance
~~~~~~~~~~~~~~~~~~~~~~~
+9 -1
View File
@@ -71,7 +71,15 @@ class Twig_Node_Module extends Twig_Node
if (null === $this->getNode('parent')) {
$compiler->raw("false");
} else {
$compiler->subcompile($this->getNode('parent'));
if ($this->getNode('parent') instanceof Twig_Node_Expression_Constant) {
$compiler->subcompile($this->getNode('parent'));
} else {
$compiler
->raw("\$this->env->resolveTemplate(")
->subcompile($this->getNode('parent'))
->raw(")")
;
}
}
$compiler
@@ -0,0 +1,12 @@
--TEST--
"extends" tag
--TEMPLATE--
{% extends ["foo.twig", "bar.twig"] %}
--TEMPLATE(bar.twig)--
{% block content %}
foo
{% endblock %}
--DATA--
return array()
--EXPECT--
foo
+1 -1
View File
@@ -149,7 +149,7 @@ class __TwigTemplate_be925a7b06dda0dfdbd18a1509f7eb34 extends Twig_Template
{
protected function doGetParent(array \$context)
{
return ((true) ? ("foo") : ("foo"));
return \$this->env->resolveTemplate(((true) ? ("foo") : ("foo")));
}
protected function doDisplay(array \$context, array \$blocks = array())