Home » Php » php – Symfony2: how to override core template?

php – Symfony2: how to override core template?

Posted by: admin July 12, 2020 Leave a comment


I am trying to override SymfonyGeneratorBundle templates by creating


That file should replace:


But it still uses original file even after cache:clear. How to do that w/o creating new bundle like Can't override the standard skeleton views in Symfony2 GeneratorBundle?

How to&Answers:

Register your bundle right after SensioGeneratorBundle in app/AppKernel.php e.g.:

// 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 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');


You have to copy skeleton folder to YourBundle\Resource and modify templates.


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


for the directory:


Now, just generate crud with the default command and it will use the new template.


The answer of m2mdas worked for me, but only after discovering that it should read

Filesystem instead of FileSystem!

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