2

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 ? :)

Gaylord.P
  • 1,539
  • 2
  • 24
  • 54

1 Answers1

1

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/
romaricdrigon
  • 1,497
  • 12
  • 16
  • 1
    Thanks ! my mistake is to have added "Bundle" term : "SymfonyFormFontAwesomeBundle::theme.html.twig" :) – Gaylord.P Feb 28 '18 at 13:52