I want to return an HTML snippet as well as other values in a json string, here is what I have:
$html = $this->render('sometemplate.html.twig', array( 'somevar' => $somevar ) );
$response = new Response(json_encode( array("html" => $html, "name" => "Joe Bloggs") ));
$response->headers->set('Content-Type', 'application/json');
return $response;
But all I get is {"html":{"headers":{}}}. Is there a way to just grab the rendered HTML?
Use
$this->renderView()instead.$this->render()returns aResponseobject, while$this->renderView()returns a string resulting from rendering a template.