Symfony: Rendering a TWIG template without headers for special template output

Rendering a TWIG template without a header in Symfony is a task you’ll end up doing in your projects. You may also capture TWIG renders into strings before they get sent to the screen. If you render templates normally with the “render” method, you’ll see the headers output to your screen like so:

HTTP/1.0 200 OK Cache-Control: no-cache Date...

It’s as easy as changing “render()” to “renderView()”, this tells Symfony to skip the headers. This is handy:

... ->renderView('template'); // instead of render('template')

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *