Skip to content

Commit 27af27f

Browse files
committed
minor #382 Fixed the way we get the Twig template source (javiereguiluz)
This PR was merged into the master branch. Discussion ---------- Fixed the way we get the Twig template source This reverts the temporary #356 solution thanks to this fix made by Twig 1.25.0 version: twigphp/Twig#2011 Commits ------- 31fd935 Fixed the way we get the Twig template source
2 parents a149223 + 31fd935 commit 27af27f

File tree

3 files changed

+16
-23
lines changed

3 files changed

+16
-23
lines changed

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
"symfony/swiftmailer-bundle" : "^2.3",
2929
"symfony/symfony" : "^3.1",
3030
"twig/extensions" : "^1.3",
31+
"twig/twig" : "^1.25",
3132
"white-october/pagerfanta-bundle" : "^1.0"
3233
},
3334
"require-dev": {

composer.lock

Lines changed: 8 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/CodeExplorerBundle/Twig/SourceCodeExtension.php

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -99,23 +99,15 @@ 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-
115102
return [
116-
'file_path' => $filePath,
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(),
117109
'starting_line' => 1,
118-
'source_code' => $sourceCode,
110+
'source_code' => $template->getSource(),
119111
];
120112
}
121113

0 commit comments

Comments
 (0)