Skip to content

Commit

Permalink
bug #1579 Fixed regression for dynamic parent (hason)
Browse files Browse the repository at this point in the history
This PR was merged into the 1.16-dev branch.

Discussion
----------

Fixed regression for dynamic parent

Fixes #1578

Commits
-------

d2fc98d Fixed regression for dynamic parent
  • Loading branch information
fabpot committed Dec 25, 2014
2 parents 2615ae3 + d2fc98d commit 4d97a91
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
16 changes: 15 additions & 1 deletion lib/Twig/Template.php
Expand Up @@ -20,6 +20,7 @@ abstract class Twig_Template implements Twig_TemplateInterface
protected static $cache = array();

protected $parent;
protected $parents = array();
protected $env;
protected $blocks;
protected $traits;
Expand Down Expand Up @@ -67,13 +68,26 @@ public function getParent(array $context)

try {
$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) {
$e->setTemplateFile(null);
$e->guess();

throw $e;
}

return $this->parents[$parent];
}

protected function doGetParent(array $context)
Expand Down
22 changes: 22 additions & 0 deletions test/Twig/Tests/Fixtures/tags/inheritance/multiple_dynamic.test
@@ -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

0 comments on commit 4d97a91

Please sign in to comment.