Skip to main content

Symfony template locations: questioning the best practice

A while ago the Symfony project published a “Best Practices” book.

This is a source of excellent suggestions and it’s written by the people who wrote Symfony in the first place, so we decided to stick to it as much as possible, even in those few cases where the benefits where not immediately clear.

But after a few more Symfony projects, there is one best practice that I definitely want to question: the location of the templates.

What do the official best practices say?

The book says they should reside in /app/Resources/views. The main benefits are:

  1. you get shorter logical names
  2. they are not distributed amongs the bundles, but stored in single location

Is this really the best approach?

While the first point is definitely true, the second loses its meaning since, elsewhere in the book, it is suggested to have a single bundle in your application.

If you follow the best practices, during development you’ll keep jumping from /src/AppBundle to /app/Resources/views and back.

Also, the /app folder contains a lot of miscellanous things:

  • configurations
  • translations
  • overrides
  • temporary folders (cache and logs)

I don’t know about you, but I see all these as the extra parts required to makes Symfony work, while the templates are a core part of my application and as such, I definitely feel it’s more logic to have them in the /src folder.

A big bonus of this approach is that you can simply delete and recreate the /src folder on deploy, since it’s got nothing that should last between deploys (this avoids issues about leaving obsolete files around).


Starting from my next project I will move the templates back into /src/AppBundle/Resources/views.

That’s my best practice 🙂