From: Henry Smith Date: Tue, 16 Jul 2013 21:08:51 +0000 (+0100) Subject: Fix for {% embed %} error line number bug X-Git-Url: http://git.silmor.de/gitweb/?a=commitdiff_plain;h=270b791ed33d4b11e7c416656985ed9c09eb715c;p=web%2Fkonrad%2Ftwig.git Fix for {% embed %} error line number bug --- diff --git a/lib/Twig/Error.php b/lib/Twig/Error.php index 72d91a9..61a4cfa 100644 --- a/lib/Twig/Error.php +++ b/lib/Twig/Error.php @@ -186,6 +186,7 @@ class Twig_Error extends Exception protected function guessTemplateInfo() { $template = null; + $templateClass = null; if (version_compare(phpversion(), '5.3.6', '>=')) { $backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS | DEBUG_BACKTRACE_PROVIDE_OBJECT); @@ -195,8 +196,11 @@ class Twig_Error extends Exception foreach ($backtrace as $trace) { if (isset($trace['object']) && $trace['object'] instanceof Twig_Template && 'Twig_Template' !== get_class($trace['object'])) { - if (null === $this->filename || $this->filename == $trace['object']->getTemplateName()) { + $currentClass = get_class($trace['object']); + $isEmbedContainer = 0 === strpos($templateClass, $currentClass); + if (null === $this->filename || ($this->filename == $trace['object']->getTemplateName() && !$isEmbedContainer)) { $template = $trace['object']; + $templateClass = get_class($trace['object']); } } } diff --git a/test/Twig/Tests/Fixtures/tags/embed/error_line.test b/test/Twig/Tests/Fixtures/tags/embed/error_line.test new file mode 100644 index 0000000..71ab2e0 --- /dev/null +++ b/test/Twig/Tests/Fixtures/tags/embed/error_line.test @@ -0,0 +1,16 @@ +--TEST-- +"embed" tag +--TEMPLATE(index.twig)-- +FOO +{% embed "foo.twig" %} + {% block c1 %} + {{ nothing }} + {% endblock %} +{% endembed %} +BAR +--TEMPLATE(foo.twig)-- +{% block c1 %}{% endblock %} +--DATA-- +return array() +--EXCEPTION-- +Twig_Error_Runtime: Variable "nothing" does not exist in "index.twig" at line 5