maximebf / php-debugbar

Debug bar for PHP
phpdebugbar.com
MIT License
4.18k stars 399 forks source link

Error extending templates (Conditional Inheritance) #330

Open manusreload opened 7 years ago

manusreload commented 7 years ago

If you do a conditional inheritance (https://twig.sensiolabs.org/doc/2.x/tags/extends.html#conditional-inheritance) the resolved template is "".

Template File

{% extends this.response.ajax == true ? "templates/modal.twig" : "templates/base.twig" %}

{% block title %}Pendiente{% endblock %}
{% block menu %}
    {% include "components/menu_taller.twig" %}
{% endblock %}
{% block body %}
...

Exception throws

Unable to find template "" (looked into: ././modules/glplanning/view, ././modules/glplanning/view/includes, ./view, ././vendor/gestionlan/framework/modules/installer/view, ././vendor/gestionlan/framework/modules/incidencias/view, ././vendor/gestionlan/framework/modules/api/views, ././vendor/gestionlan/framework/modules/admin/views, ././modules/gti/view, ././modules/notas/view, ././modules/vsustitucion/view, ././modules/vacaciones/view, /Users/manus/Dropbox/Trabajo/GestionLan/GLAutoBox/vendor/gestionlan, /Users/manus/Dropbox/Trabajo/GestionLan/GLAutoBox/vendor/gestionlan/framework, /Users/manus/Dropbox/Trabajo/GestionLan/GLAutoBox/vendor/gestionlan/framework/views, /Users/manus/Dropbox/Trabajo/GestionLan/GLAutoBox/vendor/gestionlan/framework/modules) in "/taller/pendiente.twig" at line 1.</h3> at /Users/manus/Dropbox/Trabajo/GestionLan/GLAutoBox/vendor/twig/twig/lib/Twig/Loader/Filesystem.php:232<pre>#0 /Users/manus/Dropbox/Trabajo/GestionLan/GLAutoBox/vendor/twig/twig/lib/Twig/Loader/Filesystem.php(150): Twig_Loader_Filesystem->findTemplate(Object(DebugBar\Bridge\Twig\TraceableTwigTemplate))
#1 /Users/manus/Dropbox/Trabajo/GestionLan/GLAutoBox/vendor/twig/twig/lib/Twig/Environment.php(329): Twig_Loader_Filesystem->getCacheKey(Object(DebugBar\Bridge\Twig\TraceableTwigTemplate))
#2 /Users/manus/Dropbox/Trabajo/GestionLan/GLAutoBox/vendor/maximebf/debugbar/src/DebugBar/Bridge/Twig/TraceableTwigEnvironment.php(158): Twig_Environment->getTemplateClass(Object(DebugBar\Bridge\Twig\TraceableTwigTemplate), NULL)
#3 /Users/manus/Dropbox/Trabajo/GestionLan/GLAutoBox/vendor/twig/twig/lib/Twig/Template.php(366): DebugBar\Bridge\Twig\TraceableTwigEnvironment->loadTemplate(Object(DebugBar\Bridge\Twig\TraceableTwigTemplate), NULL)
#4 /Users/manus/Dropbox/Trabajo/GestionLan/GLAutoBox/vendor/twig/twig/lib/Twig/Template.php(133): Twig_Template->loadTemplate(Object(DebugBar\Bridge\Twig\TraceableTwigTemplate))
#5 /Users/manus/Dropbox/Trabajo/GestionLan/GLAutoBox/vendor/maximebf/debugbar/src/DebugBar/Bridge/Twig/TraceableTwigEnvironment.php(167) : eval()'d code(27): Twig_Template->getParent(Array)
#6 /Users/manus/Dropbox/Trabajo/GestionLan/GLAutoBox/vendor/twig/twig/lib/Twig/Template.php(432): __TwigTemplate_9e2246e25b4c5cd5189ee7a2d3a3ca524e66fa4778e82645b1823e6e746e8add->doDisplay(Array, Array)
#7 /Users/manus/Dropbox/Trabajo/GestionLan/GLAutoBox/vendor/twig/twig/lib/Twig/Template.php(403): Twig_Template->displayWithErrorHandling(Array, Array)
#8 /Users/manus/Dropbox/Trabajo/GestionLan/GLAutoBox/vendor/maximebf/debugbar/src/DebugBar/Bridge/Twig/TraceableTwigTemplate.php(96): Twig_Template->display(Array, Array)
#9 /Users/manus/Dropbox/Trabajo/GestionLan/GLAutoBox/vendor/maximebf/debugbar/src/DebugBar/Bridge/Twig/TraceableTwigTemplate.php(115): DebugBar\Bridge\Twig\TraceableTwigTemplate->display(Array)
#10 /Users/manus/Dropbox/Trabajo/GestionLan/GLAutoBox/vendor/gestionlan/framework/src/View.php(93): DebugBar\Bridge\Twig\TraceableTwigTemplate->render(Array)

PHP Version

PHP 5.6.30 (cli) (built: Mar 11 2017 09:56:18) 
Copyright (c) 1997-2016 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies
    with Xdebug v2.3.2, Copyright (c) 2002-2015, by Derick Rethans

composer info

maximebf/debugbar                  1.13.1             Debug bar in the browser for php application

Also I noticed that the next template also throws the same exception:

{% extends extendsName %}

{% block title %}{{ this.vehiculosTaller | length }} Vehiculos{% endblock %}
{% block menu %}
    {% include "components/menu_taller.twig" %}
{% endblock %}
{% block body %}

I guess that the problem is if the "template name" is not a string then does not resolve.

Thanks!

gsouf commented 7 years ago

This is because of twig checking for wrapping TwigTemplate being an instanceOf self, and of course it fails https://github.com/twigphp/Twig/blob/v2.3.2/lib/Twig/Template.php#L92