diff --git a/lib/Twig/Template.php b/lib/Twig/Template.php index 1d54bb13a..86094e2da 100644 --- a/lib/Twig/Template.php +++ b/lib/Twig/Template.php @@ -255,7 +255,14 @@ abstract class Twig_Template implements Twig_TemplateInterface return $this->env->loadTemplate($template, $index); } catch (Twig_Error $e) { - $e->setTemplateFile($templateName ? $templateName : $this->getTemplateName()); + if (!$e->getTemplateFile()) { + $e->setTemplateFile($templateName ? $templateName : $this->getTemplateName()); + } + + if ($e->getTemplateLine()) { + throw $e; + } + if (!$line) { $e->guess(); } else { diff --git a/test/Twig/Tests/Fixtures/exceptions/syntax_error_in_reused_template.test b/test/Twig/Tests/Fixtures/exceptions/syntax_error_in_reused_template.test new file mode 100644 index 000000000..5dd9f3838 --- /dev/null +++ b/test/Twig/Tests/Fixtures/exceptions/syntax_error_in_reused_template.test @@ -0,0 +1,10 @@ +--TEST-- +Exception for syntax error in reused template +--TEMPLATE-- +{% use 'foo.twig' %} +--TEMPLATE(foo.twig)-- +{% block bar %} + {% do node.data = 5 %} +{% endblock %} +--EXCEPTION-- +Twig_Error_Syntax: Unexpected token "operator" of value "=" ("end of statement block" expected) in "foo.twig" at line 3