because bundle inheritance is deprecated since Symfony 3.4 and will be removed in 4.0, I\'m finding a new solution. I have:
I will show how it looks in my case(Symfony 5.1). To overwrite views for bundles JMoseCommandSchedulerBudnle
and TwigBundle
:
1. Create your own directory with custom third party bundle templates(I put them In Resources/views/bundles
):
2. Create folders for each bundle where you want to override templates:
3. Create custom templates(for example to create custom Twig Error Pages):
4. Implement PrependExtensionInterface
and add custom paths to the Twig Extension configuration:
class AppngCmsExtension extends Extension implements PrependExtensionInterface {
public function load(array $configs, ContainerBuilder $container)
{
$loader = new YamlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config'));
$loader->load('services.yaml');
}
public function prepend(ContainerBuilder $container)
{
// I recommend using FileLocator here
$thirdPartyBundlesViewFileLocator = (new FileLocator(__DIR__ . '/../Resources/views/bundles'));
$container->loadFromExtension('twig', [
'paths' => [
$thirdPartyBundlesViewFileLocator->locate('JMoseCommandSchedulerBundle') => 'JMoseCommandScheduler',
$thirdPartyBundlesViewFileLocator->locate('TwigBundle') => 'Twig',
],
]);
}
}