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')

About Author:

Senior Cloud Software Engineer and 25+ years experienced video production, video editing and 3D animation services for a variety of global clients including local video production here in Jacksonville, Florida.

Leave a Comment

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