mirror of
https://github.com/twigphp/Twig.git
synced 2026-09-16 12:26:30 +00:00
Fixed regression for dynamic parent
This commit is contained in:
+15
-1
@@ -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
|
||||||
Reference in New Issue
Block a user