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 a Response
object, while $this->renderView()
returns a string resulting from rendering a template.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With