mirror of
https://github.com/twigphp/Twig.git
synced 2026-09-13 02:46:29 +00:00
added support for an array of templates to the "extends" tag
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
|
||||
@@ -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
|
||||
@@ -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())
|
||||
|
||||
Reference in New Issue
Block a user