eZ\Publish\Core\MVC\Symfony\View\Manager::renderLocation PHP Method

renderLocation() public method

$content and $location will be injected in the selected template.
public renderLocation ( eZ\Publish\API\Repository\Values\Content\Location $location, string $viewType = ViewManagerInterface::VIEW_TYPE_FULL, array $parameters = [] ) : string
$location eZ\Publish\API\Repository\Values\Content\Location
$viewType string Variation of display for your content. Default is 'full'.
$parameters array Parameters to pass to the template called to render the view. By default, it's empty. 'location' and 'content' entries are reserved for the Location (and its Content) that is viewed.
return string
    public function renderLocation(Location $location, $viewType = ViewManagerInterface::VIEW_TYPE_FULL, $parameters = array())
    {
        if (!isset($parameters['location'])) {
            $parameters['location'] = $location;
        }
        if (!isset($parameters['content'])) {
            $parameters['content'] = $this->repository->getContentService()->loadContentByContentInfo($location->contentInfo, $this->configResolver->getParameter('languages'));
        }
        return $this->renderContent($parameters['content'], $viewType, $parameters);
    }

Usage Example

 public function testRenderLocationWithClosure()
 {
     $viewProvider = $this->getMock('eZ\\Publish\\Core\\MVC\\Symfony\\View\\Provider\\Location');
     $this->viewManager->addLocationViewProvider($viewProvider);
     $location = $this->getMock('eZ\\Publish\\API\\Repository\\Values\\Content\\Location');
     $content = $this->getMock('eZ\\Publish\\API\\Repository\\Values\\Content\\Content');
     $contentInfo = $this->getMock('eZ\\Publish\\API\\Repository\\Values\\Content\\ContentInfo');
     // Configuring view provider behaviour
     $closure = function ($params) {
         return serialize(array_keys($params));
     };
     $params = array('foo' => 'bar');
     $viewProvider->expects($this->once())->method('getView')->with($location)->will($this->returnValue(new ContentView($closure, $params)));
     $contentService = $this->getMockBuilder("eZ\\Publish\\Core\\Repository\\ContentService")->disableOriginalConstructor()->getMock();
     $contentService->expects($this->any())->method("loadContentByContentInfo")->with($contentInfo)->will($this->returnValue($content));
     $this->repositoryMock->expects($this->any())->method("getContentService")->will($this->returnValue($contentService));
     $location->expects($this->any())->method("getContentInfo")->will($this->returnValue($contentInfo));
     // Configuring template engine behaviour
     $params += array('location' => $location, 'content' => $content, 'viewbaseLayout' => $this->viewBaseLayout);
     $expectedTemplateResult = serialize(array_keys($params));
     $this->templateEngineMock->expects($this->never())->method('render');
     self::assertSame($expectedTemplateResult, $this->viewManager->renderLocation($location));
 }
All Usage Examples Of eZ\Publish\Core\MVC\Symfony\View\Manager::renderLocation