Fixed regression for dynamic parent

This commit is contained in:
Martin Hasoň
2014-12-08 16:38:15 +01:00
parent a1b847b3a3
commit d2fc98d026
2 changed files with 37 additions and 1 deletions
+15 -1
View File
@@ -20,6 +20,7 @@ abstract class Twig_Template implements Twig_TemplateInterface
protected static $cache = array(); protected static $cache = array();
protected $parent; protected $parent;
protected $parents = array();
protected $env; protected $env;
protected $blocks; protected $blocks;
protected $traits; protected $traits;
@@ -67,13 +68,26 @@ abstract class Twig_Template implements Twig_TemplateInterface
try { try {
$parent = $this->doGetParent($context); $parent = $this->doGetParent($context);
return $this->parent = false === $parent ? false : $this->env->resolveTemplate($parent);
if (false === $parent) {
return false;
}
if ($parent instanceof Twig_Template) {
return $this->parents[$parent->getTemplateName()] = $parent;
}
if (!isset($this->parents[$parent])) {
$this->parents[$parent] = $this->env->loadTemplate($parent);
}
} catch (Twig_Error_Loader $e) { } catch (Twig_Error_Loader $e) {
$e->setTemplateFile(null); $e->setTemplateFile(null);
$e->guess(); $e->guess();
throw $e; throw $e;
} }
return $this->parents[$parent];
} }
protected function doGetParent(array $context) protected function doGetParent(array $context)
@@ -0,0 +1,22 @@
--TEST--
"extends" tag
--TEMPLATE--
{% set foo = 1 %}
{{ include('parent.twig') }}
{{ include('parent.twig') }}
{% set foo = 2 %}
{{ include('parent.twig') }}
--TEMPLATE(parent.twig)--
{% extends foo~'_parent.twig' %}{% block content %}{{ parent() }} parent{% endblock %}
--TEMPLATE(1_parent.twig)--
{% block content %}1{% endblock %}
--TEMPLATE(2_parent.twig)--
{% block content %}2{% endblock %}
--DATA--
return array()
--EXPECT--
1 parent
1 parent
2 parent