Symfony2: how to override the main template?

I am trying to override SymfonyGeneratorBundle patterns by creating

\app\Resources\SensioGeneratorBundle\skeleton\crud\views\index.html.twig 

This file should replace:

 \vendor\bundles\Sensio\Bundle\GeneratorBundle\Resources\skeleton\crud\views\index.html.twig 

But it still uses the original file even after cache:clear. How to do this without creating a new package, for example It is impossible to override the standard skeleton views in the Symfony2 GeneratorBundle

+7
source share
3 answers

Register your package immediately after the SensioGeneratorBundle in app/AppKernel.php for example:

 // app/AppKernel.php if (in_array($this->getEnvironment(), array('dev', 'test'))) { //..... $bundles[] = new Sensio\Bundle\GeneratorBundle\SensioGeneratorBundle(); $bundles[] = new Namespace\YourBundle(); } // Or outside if, should you want your bundle to be available in production environment $bundles[] = new Namespace\YourBundle(); 

Then in YourBundle.php override the registerCommands method,

 // Bundle\YourBundle.php // other declarations use Symfony\Component\Console\Application; use Sensio\Bundle\GeneratorBundle\Generator\DoctrineCrudGenerator; use Symfony\Component\Filesystem\Filesystem; public function registerCommands(Application $application){ $crudCommand = $application->get('generate:doctrine:crud'); $generator = new DoctrineCrudGenerator(new FileSystem, __DIR__.'/Resources/skeleton/crud'); $crudCommand->setGenerator($generator); parent::registerCommands($application); } 

You need to copy the skeleton folder to YourBundle\Resource and change the templates.

+14
source

To override the editing template, for example, in version 2.3+, copy the file:

 vendor/sensio/generator-bundle/Sensio/Bundle/GeneratorBundle/Resources/skeleton/crud/views/edit.html.twig.twig 

for the catalog:

 app/Resources/SensioGeneratorBundle/skeleton/crud/views/edit.html.twig.twig 

Now just create crud using the default command and it will use the new template.

+11
source

M2mdas answer worked for me, but only after discovering that it should read

File system instead of FileSystem!

Take a look at the /symfony/.../Filesystem vendors folder to verify this.

0
source

All Articles