eZ\Publish\Core\MVC\Symfony\Controller\Controller::render PHP Method

render() public method

Renders a view.
public render ( string $view, array $parameters = [], Response $response = null ) : Response
$view string The view name
$parameters array An array of parameters to pass to the view
$response Symfony\Component\HttpFoundation\Response
return Symfony\Component\HttpFoundation\Response
    public function render($view, array $parameters = array(), Response $response = null)
    {
        if (!isset($response)) {
            $response = new Response();
        }
        $response->setContent($this->getTemplateEngine()->render($view, $parameters));
        return $response;
    }

Usage Example

 public function testRenderWithResponse()
 {
     $response = new Response();
     $view = 'some:valid:view.html.twig';
     $params = array('foo' => 'bar', 'truc' => 'muche');
     $tplResult = "I'm a template result";
     $this->templateEngineMock->expects($this->once())->method('render')->with($view, $params)->will($this->returnValue($tplResult));
     self::assertSame($response, $this->controller->render($view, $params, $response));
     self::assertSame($tplResult, $response->getContent());
 }