Controlling whitespace in Twig
Recently I discovered the finer controls for whitespace within twig, beyond just the 'spaceless' option.
Recently I discovered the finer controls for whitespace within twig, beyond just the 'spaceless' option.
In a recent project of ours, we needed to conditionally link a CSS file if it existed for a given tenant within a multi-tenant system. We didn't want to have every controller or action have to check for this file and pass the results to Twig. Luckily for us, there's a better way!
Twig will sometimes escape output, which can be a real problem if you're relying on it to build your web page or provide data to something like a piece of JavaScript. Twig's raw provides an easy solution to this, but opens up a realm of potential security issues leaving you more vulnerable than you think. Here's another solution to help you stay secure and get the job done.