$template = null;
foreach (debug_backtrace() as $trace) {
if (isset($trace['object']) && $trace['object'] instanceof Twig_Template && 'Twig_Template' !== get_class($trace['object'])) {
- $template = $trace['object'];
+ if (null === $this->filename || $this->filename == $trace['object']->getTemplateName()) {
+ $template = $trace['object'];
+ }
}
}
return null;
}
- throw new Twig_Error_Runtime(sprintf('Variable "%s" does not exist', $item));
+ throw new Twig_Error_Runtime(sprintf('Variable "%s" does not exist', $item), -1, $this->getTemplateName());
}
return $context[$item];
}
}
+ public function testTwigExceptionAddsFileAndLineWhenMissingWithInheritanceAgain()
+ {
+ $loader = new Twig_Loader_Array(array(
+ 'index' => "{% extends 'base' %}
+ {% block content %}
+ {{ parent() }}
+ {% endblock %}",
+ 'base' => '{% block content %}{{ foo }}{% endblock %}'
+ ));
+ $twig = new Twig_Environment($loader, array('strict_variables' => true, 'debug' => true, 'cache' => false));
+
+ $template = $twig->loadTemplate('index');
+ try {
+ $template->render(array());
+
+ $this->fail();
+ } catch (Twig_Error_Runtime $e) {
+ $this->assertEquals('Variable "foo" does not exist in "base" at line 1', $e->getMessage());
+ $this->assertEquals(1, $e->getTemplateLine());
+ $this->assertEquals('base', $e->getTemplateFile());
+ }
+ }
+
public function testTwigExceptionAddsFileAndLineWhenMissingWithInheritanceOnDisk()
{
$loader = new Twig_Loader_Filesystem(dirname(__FILE__).'/Fixtures/errors');