* 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
$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
~~~~~~~~~~~~~~~~~~~~~~~
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
--- /dev/null
+--TEST--
+"extends" tag
+--TEMPLATE--
+{% extends ["foo.twig", "bar.twig"] %}
+--TEMPLATE(bar.twig)--
+{% block content %}
+foo
+{% endblock %}
+--DATA--
+return array()
+--EXPECT--
+foo
{
protected function doGetParent(array \$context)
{
- return ((true) ? ("foo") : ("foo"));
+ return \$this->env->resolveTemplate(((true) ? ("foo") : ("foo")));
}
protected function doDisplay(array \$context, array \$blocks = array())