ed2*_*209 23 php json symfony twig
我想返回一个HTML片段以及json字符串中的其他值,这是我所拥有的:
$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;
Run Code Online (Sandbox Code Playgroud)
但我得到的只是{"html":{"headers":{}}}.有没有办法只抓取渲染的HTML?
Eln*_*mov 46
请$this->renderView()改用.
$this->render()返回一个Response对象,同时$this->renderView()返回一个由渲染模板产生的字符串.