8000 [TwigBundle] Added auto namespacing for new templates directory structure by HeahDude · Pull Request #23339 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[TwigBundle] Added auto namespacing for new templates directory structure #23339

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,9 @@ private function addTwigOptions(ArrayNodeDefinition $rootNode)
->end()
->prototype('variable')->end()
->end()
->scalarNode('default_path')
->defaultValue('%kernel.project_dir%/templates')
->end()
->end()
;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,12 +122,16 @@ public function load(array $configs, ContainerBuilder $container)
foreach ($bundle['paths'] as $path) {
$twigFilesystemLoaderDefinition->addMethodCall('addPath', array($path, $namespace));
}

$twigFilesystemLoaderDefinition->addMethodCall('addPath', array($config['default_path'].'/bundles/'.$namespace, $namespace));
Copy link
Member
@yceruto yceruto Jul 27, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This path should be added before the bundle path, (here https://github.com/HeahDude/symfony/blob/851aee62eb905c8d1390a12f7f3a56fce5b8abe8/src/Symfony/Bundle/TwigBundle/DependencyInjection/TwigExtension.php#L195):

// ---------> here <---------

if ($container->fileExists($dir = $bundle['path'].'/Resources/views', false)) {
    $bundleHierarchy[$name]['paths'][] = $dir;
}

Otherwise we can't able to override templates from third-party bundles, because the parent template will be loaded first always.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also the path needs to be checked if it exists before add it, otherwise Twig throw an exception:

[Twig_Error_Loader]                                                                                                                      
  The "templates/bundles/Twig" directory does not exist ("/home/yceruto/github/symfony/symfony-demo/templates/bundles/Twig"). 

}

if ($container->fileExists($dir = $container->getParameter('kernel.root_dir').'/Resources/views', false)) {
$twigFilesystemLoaderDefinition->addMethodCall('addPath', array($dir));
}

$twigFilesystemLoaderDefinition->addMethodCall('addPath', array($config['default_path']));

if (!empty($config['globals'])) {
$def = $container->getDefinition('twig');
foreach ($config['globals'] as $key => $global) {
Expand Down
0