Code Snippets
Twig & Doctrine
Templates and mappings, which is where the time actually goes - Twig syntax, escaping, and the Doctrine queries behind what a template renders.
Filter these 6 posts
Everything in Twig & Doctrine

09/02/2026
Twig autoescaping and the raw filter
Autoescaping makes Twig safe by default and makes |raw the fastest way to undo that. The catch is that HTML escaping is only correct in HTML - inside a script tag or an unquoted attribute, the default is the wrong answer.

09/02/2026
The N+1 you wrote in a Twig loop, and its fix
The query looks fine and the template looks fine. Together they issue one query per row, because a lazy association is loaded the moment a template touches it - and templates touch things the controller never did.

07/04/2019
Rendering a Twig template outside a controller
You do not need a controller to render Twig, and you should not pass the container around to get at it. Inject the Environment, and use createTemplate when the template itself comes from the database.

04/02/2015
How to show or access cookie values in Symfony Twig views
Strange how obscure it is to find a clear example of how to just access or show the value of a cookie in Twig, so here it is!

09/04/2014
Doctrine's equivalent of SQL IN()
MySQL’s “IN” query filter is very useful. Basically, if you have a list of record ID numbers, you can query them all neatly like so:

06/24/2014
Symfony collection prototype: formatting it in Twig
Let’s say you are creating a form in Symfony that has some dynamic fields that you need to allow the user to add and remove a subset of options and fields from within the form.