Search code examples
phpsymfonypartialhttp-status-codes

Render a template with a specific status code


Since I've read that Chrome is having trouble looping an HTML5 video if the response code isn't 206, I'd like to render my template with a 206 code.

Yet I've not found anywhere how to specify an html code when rendering a template... Did anyone already tried that and succeeded ?


Solution

  • In the controller you can create and return a Response object with the content and the specified return code, as example:

    return new Response(
        $this->renderView('AcmeDemoBundle:Default:video.html.twig', array(
                'param1'    => $param1,
                'param2'     => $param2,
            )),
            206  // return code
    );
    

    Hope this help