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

renderBlock() public method

$block will be injected in the selected template.
public renderBlock ( Block $block, array $parameters = [] ) : string
$block eZ\Publish\Core\FieldType\Page\Parts\Block
$parameters array Parameters to pass to the template called to render the view. By default, it's empty. 'block' entry is reserved for the Block that is viewed.
return string
    public function renderBlock(Block $block, $parameters = array())
    {
        $view = new BlockView(null, $parameters);
        $view->setBlock($block);
        $this->viewConfigurator->configure($view);
        if ($view->getTemplateIdentifier() === null) {
            throw new RuntimeException("Unable to find a view for location #{$block->id}");
        }
        return $this->renderContentView($view);
    }

Usage Example

Example #1
0
 /**
  * Render the block
  *
  * @param \eZ\Publish\Core\FieldType\Page\Parts\Block $block
  * @param array $params
  * @param array $cacheSettings settings for the HTTP cache, 'smax-age' and
  *        'max-age' are checked.
  *
  * @return \Symfony\Component\HttpFoundation\Response
  */
 public function viewBlock(Block $block, array $params = array(), array $cacheSettings = array())
 {
     $response = new Response();
     if ($this->getParameter('content.view_cache') === true) {
         $response->setPublic();
         if (isset($cacheSettings['smax-age']) && is_int($cacheSettings['smax-age'])) {
             $response->setSharedMaxAge((int) $cacheSettings['smax-age']);
         }
         if (isset($cacheSettings['max-age']) && is_int($cacheSettings['max-age'])) {
             $response->setMaxAge((int) $cacheSettings['max-age']);
         }
     }
     $response->setContent($this->viewManager->renderBlock($block, $params + array('pageService' => $this->pageService, 'valid_items' => $this->pageService->getValidBlockItems($block))));
     return $response;
 }