Skip to content

Commit

Permalink
Fixed error guessing in blocks in a child template
Browse files Browse the repository at this point in the history
  • Loading branch information
hason committed Jul 31, 2015
1 parent 1ded65d commit cfa1404
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
11 changes: 11 additions & 0 deletions lib/Twig/Template.php
Expand Up @@ -155,6 +155,17 @@ public function displayBlock($name, array $context, array $blocks = array(), $us
try {
$template->$block($context, $blocks);
} catch (Twig_Error $e) {
if (!$e->getTemplateFile()) {
$e->setTemplateFile($template->getTemplateName());
}

// this is mostly useful for Twig_Error_Loader exceptions
// see Twig_Error_Loader
if (false === $e->getTemplateLine()) {
$e->setTemplateLine(-1);
$e->guess();
}

throw $e;
} catch (Exception $e) {
throw new Twig_Error_Runtime(sprintf('An exception has been thrown during the rendering of a template ("%s").', $e->getMessage()), -1, $template->getTemplateName(), $e);
Expand Down
@@ -0,0 +1,15 @@
--TEST--
Exception for an undefined template in a child template
--TEMPLATE--
{% extends 'base.twig' %}

{% block sidebar %}
{{ include('include.twig') }}
{% endblock %}
--TEMPLATE(base.twig)--
{% block sidebar %}
{% endblock %}
--DATA--
return array()
--EXCEPTION--
Twig_Error_Loader: Template "include.twig" is not defined in "index.twig" at line 5.

0 comments on commit cfa1404

Please sign in to comment.