What do the new Symfony “Best Practices” mean for frontend developers?

This article is part of a series; see Symfony for frontend developers for more.

The Symfony team recently published a Best Practices document outlining their recommendations for all sorts of things about how Symfony applications should be developed.

If your team has adopted these best practices, what will that mean for you as a frontend developer?  In short, it’ll change a lot about where files are found.

NB You should discuss with your team what folder structure your project follows – many projects will be using the older Symfony folder structure, or some other structure of their own, and you should follow the project’s convention in the first instance.  This post is just to explain what the new recommendations are, to save you having to read the full Best Practices document!

Templates

Previously, you’d find templates in a bundle, so they’d be somewhere like src/MyProj/AdminBundle/Resources/views/layout.html.twig

The new recommendation is that all templates go in subfolders under app/Resources/views instead.

Assets

You’ll remember from the article “Symfony for frontend developers #1 – where are my files?!” that my advice was to ignore the web folder when hunting for files to edit.  In “Symfony for frontend developers #5 – Assets and Assetic”, I explained how assets end up in web thanks to symlinks back to the relevant bundle folders under src.

The approach suggested in the Best Practices is simpler – web assets such as stylesheets, javascript files and images will actually live in (subfolders of) the web folder itself.  As with the asset subfolders under src, you can call those subfolders of web whatever you like.

Bundles

As a frontend developer, you won’t need to go into the application code in the bundle folders under src very often.  And with templates being moved into app/Resources, that’s one less reason to delve into bundles.

However, as I outlined in “Symfony for frontend developers #3 – Setting Twig variables”, you’ll sometimes need to look in your application’s controller files to find out where the value of a Twig variable is set.

That doesn’t change with the adoption of the Best Practices.  However, one interesting recommendation in the Best Practices document is that most sites should only have one bundle, called AppBundle.

Furthermore, In Symfony 3 (a long way off being released, but some people are using its folder structure already), the code will found directly in src, not in a bundle at all.

Of course, as you’ve read article #3 in this series, you’ll know all about using the Symfony toolbar to find your controller files quickly anyway!  However, this move to a single bundle may simplify things for you nonetheless.

Conclusion

Whilst the Symfony Best Practices aren’t going to be adopted overnight, it’s likely that we’ll see more projects following at least some of their recommendations.  By knowing what impact the recommendations will have on where different types of files can be found, you’ll be ready for the day when you start styling a new project and find that everything has been moved around!

One Comment

  1. Posted 4 November 2014 at 2:06 pm | Permalink

    I will further store templates in the bundle directory. For me it’s more logical. In the global resources directory im only storing templates of other bundles, like FOSUserBundle … which i overwrite.

Post a Comment

Your email address is never published nor shared. Required fields are marked *

Ready to talk?

Whether you want to create a new digital product or make an existing one even better, we'd love to talk it through.

Get in touch