Add exclusive Twig namespace for bundles path

This commit is contained in:
Yonel Ceruto 2017-09-19 13:13:19 -04:00
parent ad4bc6b647
commit 0a658c6eef
3 changed files with 9 additions and 0 deletions

View File

@ -4,6 +4,7 @@ CHANGELOG
3.4.0
-----
* added exclusive Twig namespace only for root bundles
* deprecated `Symfony\Bundle\TwigBundle\Command\DebugCommand`, use `Symfony\Bridge\Twig\Command\DebugCommand` instead
* deprecated relying on the `ContainerAwareInterface` implementation for `Symfony\Bundle\TwigBundle\Command\LintCommand`
* added option to configure default path templates (via `default_path`)

View File

@ -130,6 +130,13 @@ class TwigExtension extends Extension
foreach ($bundle['paths'] as $path) {
$twigFilesystemLoaderDefinition->addMethodCall('addPath', array($path, $namespace));
}
// add exclusive namespace for root bundles only
// to override a bundle template that also extends itself
if (count($bundle['paths']) > 0 && 0 === count($bundle['parents'])) {
// the last path must be the bundle views directory
$twigFilesystemLoaderDefinition->addMethodCall('addPath', array(end($bundle['paths']), '!'.$namespace));
}
}
if (file_exists($dir = $container->getParameter('kernel.root_dir').'/Resources/views')) {

View File

@ -198,6 +198,7 @@ class TwigExtensionTest extends TestCase
array(__DIR__.'/Fixtures/Resources/TwigBundle/views', 'Twig'),
array(__DIR__.'/Fixtures/templates/bundles/TwigBundle', 'Twig'),
array(realpath(__DIR__.'/../..').'/Resources/views', 'Twig'),
array(realpath(__DIR__.'/../..').'/Resources/views', '!Twig'),
array(__DIR__.'/Fixtures/Bundle/ChildChildChildChildTwigBundle/Resources/views', 'ChildTwig'),
array(__DIR__.'/Fixtures/Bundle/ChildChildChildTwigBundle/Resources/views', 'ChildTwig'),
array(__DIR__.'/Fixtures/Bundle/ChildChildTwigBundle/Resources/views', 'ChildTwig'),