Skip to content

Commit 284ebc6

Browse files
committed
bug #356 Add a temporary workaround for an issue #224 (voronkovich)
This PR was squashed before being merged into the master branch (closes #356). Discussion ---------- Add a temporary workaround for an issue #224 See #224 Commits ------- 2ff4737 Add a temporary workaround for an issue #224
2 parents 0edb2b9 + 2ff4737 commit 284ebc6

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

src/CodeExplorerBundle/Twig/SourceCodeExtension.php

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -99,15 +99,23 @@ private function getCallableReflector($callable)
9999

100100
private function getTemplateSource(\Twig_Template $template)
101101
{
102+
// Twig templates are not always stored in files, and so there is no
103+
// API to get the filename from a template name in a generic way.
104+
// The logic used here works only for templates stored in app/Resources/views
105+
// and referenced via the "filename.html.twig" notation, not via the "::filename.html.twig"
106+
// one or stored in bundles. This is enough for the needs of the demo app.
107+
$filePath = $this->kernelRootDir.'/Resources/views/'.$template->getTemplateName();
108+
$sourceCode = $template->getSource();
109+
110+
// Temporary workaround for https://github.com/twigphp/Twig/issues/2011
111+
if (null === $sourceCode) {
112+
$sourceCode = @file_get_contents($filePath);
113+
}
114+
102115
return [
103-
// Twig templates are not always stored in files, and so there is no
104-
// API to get the filename from a template name in a generic way.
105-
// The logic used here works only for templates stored in app/Resources/views
106-
// and referenced via the "filename.html.twig" notation, not via the "::filename.html.twig"
107-
// one or stored in bundles. This is enough for the needs of the demo app.
108-
'file_path' => $this->kernelRootDir.'/Resources/views/'.$template->getTemplateName(),
116+
'file_path' => $filePath,
109117
'starting_line' => 1,
110-
'source_code' => $template->getSource(),
118+
'source_code' => $sourceCode,
111119
];
112120
}
113121

0 commit comments

Comments
 (0)