Skip to content

Commit 7037a44

Browse files
committed
inject project root path into twig filesystem loader
1 parent 8c22de4 commit 7037a44

File tree

3 files changed

+11
-6
lines changed

3 files changed

+11
-6
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@ public function process(ContainerBuilder $container)
6464
$container->getDefinition('twig.extension.debug')->addTag('twig.extension');
6565
}
6666

67+
$loader = $container->getDefinition('twig.loader.filesystem');
68+
$loader->replaceArgument(2, $this->getComposerRootDir($container->getParameter('kernel.root_dir')));
69+
6770
if (!$container->has('templating')) {
6871
$loader = $container->getDefinition('twig.loader.native_filesystem');
6972
$loader->replaceArgument(1, $this->getComposerRootDir($container->getParameter('kernel.root_dir')));

src/Symfony/Bundle/TwigBundle/Loader/FilesystemLoader.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,13 @@ class FilesystemLoader extends \Twig_Loader_Filesystem
2929
/**
3030
* Constructor.
3131
*
32-
* @param FileLocatorInterface $locator A FileLocatorInterface instance
33-
* @param TemplateNameParserInterface $parser A TemplateNameParserInterface instance
32+
* @param FileLocatorInterface $locator A FileLocatorInterface instance
33+
* @param TemplateNameParserInterface $parser A TemplateNameParserInterface instance
34+
* @param string $rootPath The project's root dir
3435
*/
35-
public function __construct(FileLocatorInterface $locator, TemplateNameParserInterface $parser)
36+
public function __construct(FileLocatorInterface $locator, TemplateNameParserInterface $parser, $rootPath = '')
3637
{
37-
parent::__construct(array());
38+
parent::__construct(array(), $rootPath);
3839

3940
$this->locator = $locator;
4041
$this->parser = $parser;

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,13 @@
4646

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

5252
<service id="twig.loader.filesystem" class="Symfony\Bundle\TwigBundle\Loader\FilesystemLoader" public="false">
5353
<argument type="service" id="templating.locator" />
5454
<argument type="service" id="templating.name_parser" />
55+
<argument /> <!-- project's root dir -->
5556
<tag name="twig.loader"/>
5657
</service>
5758

@@ -87,7 +88,7 @@
8788

8889
<service id="twig.extension.code" class="Symfony\Bridge\Twig\Extension\CodeExtension" public="false">
8990
<tag name="twig.extension" />
90-
<argument type="service" id="debug.file_link_formatter"></argument>
91+
<argument type="service" id="debug.file_link_formatter" />
9192
<argument>%kernel.root_dir%</argument>
9293
<argument>%kernel.charset%</argument>
9394
</service>

0 commit comments

Comments
 (0)