mirror of
https://github.com/twigphp/Twig.git
synced 2026-09-15 11:56:50 +00:00
merged branch h2s/embed-error-line (PR #1140)
This PR was squashed before being merged into the master branch (closes #1140). Discussion ---------- Fix for {% embed %} error line number bug This deals with issue #958. I've gone into a lot of detail about the fix itself in the commit message for12cc0a0, so I won't repeat any of that here. Take a look and let me know what you think! Commits -------270b791Fix for {% embed %} error line number bug
This commit is contained in:
+5
-1
@@ -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']);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
Reference in New Issue
Block a user