2
votes

I want to separate my Symfony bundles. I have created SymfonyFormFontAwesomeBundle and ExtensionClass in DependencyInjection repertory :

SymfonyFormFontAwesomeExtension :

class SymfonyFormFontAwesomeExtension extends Extension
{
    public function load(array $configs, ContainerBuilder $container): void
    {
        $loader = new YamlFileLoader(
            $container,
            new FileLocator(__DIR__.'/../Resources/config')
        );
        $loader->load('services.yaml');

        $this->loadTwigTheme($container);
    }

    private function loadTwigTheme(ContainerBuilder $container)
    {
        if (!$container->hasParameter('twig.form.resources')) {
            return;
        }

        $container->setParameter('twig.form.resources', array_merge(
            [
                'SymfonyFormFontAwesomeBundle::theme.html.twig'
            ],
            $container->getParameter('twig.form.resources')
        ));
    }
}

But Symfony search theme in my projet (not in my bundle) :

Unable to find template "SymfonyFormFontAwesomeBundle::theme.html.twig" (looked into: /var/www/symfony/Project/templates, /var/www/symfony/Project/templates, /var/www/symfony/Project/vendor/symfony/twig-bridge/Resources/views/Form).

I want to load the file "theme.html.twig" that is in my bundle.

Can you help me ? :)

1
Do you load the bundle in your AppKernel.php and have you cleared your cache after adding it?lxg
Yes, and services.yaml of my bundle is well loaded :)Gaylord.P

1 Answers

1
votes

I suspect you are using Symfony4, while the code you used looks like Symfony 2 code. Since Symfony 3(.2?) the Templating component is not used anymore by Twig, so there may be changes.

I would suggest you 2 modifications:

  • instead of setting twig.form.resources, use a parameter for the config option twig.form_themes, parameter you will be able to easily modify from your bundle extension
  • use the @SymfonyFormFontAwesome::theme.html.twig syntax, otherwise SF4 will look inside templates/