diff --git a/src/Symfony/Bridge/Twig/DataCollector/TwigDataCollector.php b/src/Symfony/Bridge/Twig/DataCollector/TwigDataCollector.php index f28c92422ae48..d5efaa805362c 100644 --- a/src/Symfony/Bridge/Twig/DataCollector/TwigDataCollector.php +++ b/src/Symfony/Bridge/Twig/DataCollector/TwigDataCollector.php @@ -15,6 +15,7 @@ use Symfony\Component\HttpKernel\DataCollector\LateDataCollectorInterface; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; +use Twig\Environment; use Twig\Markup; use Twig\Profiler\Dumper\HtmlDumper; use Twig\Profiler\Profile; @@ -27,11 +28,13 @@ class TwigDataCollector extends DataCollector implements LateDataCollectorInterface { private $profile; + private $twig; private $computed; - public function __construct(Profile $profile) + public function __construct(Profile $profile, Environment $twig) { $this->profile = $profile; + $this->twig = $twig; } /** @@ -47,6 +50,17 @@ public function collect(Request $request, Response $response, \Exception $except public function lateCollect() { $this->data['profile'] = serialize($this->profile); + $this->data['template_paths'] = array(); + + $templateFinder = function (Profile $profile) use (&$templateFinder) { + if ($profile->isTemplate() && $template = $this->twig->load($profile->getName())->getSourceContext()->getPath()) { + $this->data['template_paths'][$profile->getName()] = $template; + } + foreach ($profile as $p) { + $templateFinder($p); + } + }; + $templateFinder($this->profile); } public function getTime() @@ -59,6 +73,11 @@ public function getTemplateCount() return $this->getComputedData('template_count'); } + public function getTemplatePaths() + { + return $this->data['template_paths']; + } + public function getTemplates() { return $this->getComputedData('templates'); diff --git a/src/Symfony/Bundle/TwigBundle/Resources/config/twig.xml b/src/Symfony/Bundle/TwigBundle/Resources/config/twig.xml index 8c6a944603333..ff564b412148a 100644 --- a/src/Symfony/Bundle/TwigBundle/Resources/config/twig.xml +++ b/src/Symfony/Bundle/TwigBundle/Resources/config/twig.xml @@ -68,6 +68,7 @@ + diff --git a/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Collector/twig.html.twig b/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Collector/twig.html.twig index c3c8a5d5f6764..dbf3825ee60f6 100644 --- a/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Collector/twig.html.twig +++ b/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Collector/twig.html.twig @@ -85,7 +85,9 @@ {% for template, count in collector.templates %} - {{ template }} + {%- set file = collector.templatePaths[template]|default(false) -%} + {%- set link = file ? file|file_link(1) : false -%} + {% if link %}{{ template }}{% else %}{{ template }}{% endif %} {{ count }} {% endfor %} diff --git a/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Profiler/open.css.twig b/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Profiler/open.css.twig index 7a0941c955a6d..d0f5cda02dccc 100644 --- a/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Profiler/open.css.twig +++ b/src/Symfony/Bundle/WebProfilerBundle/Resources/views/Profiler/open.css.twig @@ -58,6 +58,10 @@ a.doc:hover { margin-top: 41px; } +.source li code { + color: #555; +} + .source li.selected { background: rgba(255, 255, 153, 0.5); }