From 526b8a04fd1617591c4bb27e6c415de881aa468a Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Sun, 6 Nov 2016 12:19:52 -0800 Subject: [PATCH] [TwigBundle] fixed template root path --- .../Compiler/ExtensionPass.php | 15 +++++++++++++++ .../Bundle/TwigBundle/Resources/config/twig.xml | 2 +- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Bundle/TwigBundle/DependencyInjection/Compiler/ExtensionPass.php b/src/Symfony/Bundle/TwigBundle/DependencyInjection/Compiler/ExtensionPass.php index 316cc665a4b94..603cbe8e22ef1 100644 --- a/src/Symfony/Bundle/TwigBundle/DependencyInjection/Compiler/ExtensionPass.php +++ b/src/Symfony/Bundle/TwigBundle/DependencyInjection/Compiler/ExtensionPass.php @@ -66,6 +66,7 @@ public function process(ContainerBuilder $container) if (!$container->has('templating')) { $loader = $container->getDefinition('twig.loader.native_filesystem'); + $loader->replaceArgument(1, $this->getComposerRootDir($container->getParameter('kernel.root_dir'))); $loader->addTag('twig.loader'); $loader->setMethodCalls($container->getDefinition('twig.loader.filesystem')->getMethodCalls()); @@ -91,4 +92,18 @@ public function process(ContainerBuilder $container) $container->getDefinition('twig.extension.expression')->addTag('twig.extension'); } } + + private function getComposerRootDir($rootDir) + { + $dir = $rootDir; + while (!file_exists($dir.'/composer.json')) { + if ($dir === dirname($dir)) { + return $rootDir; + } + + $dir = dirname($dir); + } + + return $dir; + } } diff --git a/src/Symfony/Bundle/TwigBundle/Resources/config/twig.xml b/src/Symfony/Bundle/TwigBundle/Resources/config/twig.xml index fd7575ac3fe42..c82cbafbeb953 100644 --- a/src/Symfony/Bundle/TwigBundle/Resources/config/twig.xml +++ b/src/Symfony/Bundle/TwigBundle/Resources/config/twig.xml @@ -46,7 +46,7 @@ - %kernel.root_dir% +