Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 526b8a0

Browse files
committed
[TwigBundle] fixed template root path
1 parent 46a8ede commit 526b8a0

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

src/Symfony/Bundle/TwigBundle/DependencyInjection/Compiler/ExtensionPass.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ public function process(ContainerBuilder $container)
6666

6767
if (!$container->has('templating')) {
6868
$loader = $container->getDefinition('twig.loader.native_filesystem');
69+
$loader->replaceArgument(1, $this->getComposerRootDir($container->getParameter('kernel.root_dir')));
6970
$loader->addTag('twig.loader');
7071
$loader->setMethodCalls($container->getDefinition('twig.loader.filesystem')->getMethodCalls());
7172

@@ -91,4 +92,18 @@ public function process(ContainerBuilder $container)
9192
$container->getDefinition('twig.extension.expression')->addTag('twig.extension');
9293
}
9394
}
95+
96+
private function getComposerRootDir($rootDir)
97+
{
98+
$dir = $rootDir;
99+
while (!file_exists($dir.'/composer.json')) {
100+
if ($dir === dirname($dir)) {
101+
return $rootDir;
102+
}
103+
104+
$dir = dirname($dir);
105+
}
106+
107+
return $dir;
108+
}
94109
}

src/Symfony/Bundle/TwigBundle/Resources/config/twig.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646

4747
<service id="twig.loader.native_filesystem" class="Twig_Loader_Filesystem" public="false">
4848
<argument type="collection" /> <!-- paths -->
49-
<argument>%kernel.root_dir%</argument>
49+
<argument></argument> <!-- project's root dir -->
5050
</service>
5151

5252
<service id="twig.loader.filesystem" class="Symfony\Bundle\TwigBundle\Loader\FilesystemLoader" public="false">

0 commit comments

Comments
 (0)