Render a Block

@author Vincent Chalamon <vincentchalamon@gmail.com>

@param string $name Block name

@return null|string
480701
public function renderBlock($name)
    {
        /** @var Block $block */
        $block = $this->repositories['block']->findOneBy(array('name' => $name));
        if (!$block || (!$block->isPublished() && !$this->security->isGranted('ROLE_ADMIN'))) {
            return;
        }

        return $block->getContents();
    }
1116079
public static function getFormatTemplate($name) {
        $file = sprintf(
            '%s/Model/template/format/%s.html',
            __DIR__,
            $name
        );

        if (!file_exists($file)) {
            return null;
        }

        if (!isset(self::$templates[$name])) {
            self::$templates[$name] = file_get_contents($file);
        }

        return self::$templates[$name];
    }
805536
public function block($name)
    {
        $this->currentBlock = $name;

        $this->getBlockQueue()->push($name);

        // Start an output buffer.
        ob_start();
    }
518179
public function render($name, array $context = [])
    {
        $template = $this->environment->loadTemplate($name);
        return $template->render($context);
    }
614159
public function parent($name)
    {
        $placeholder = $this->placeholder($name);
        return isset($this->blocks[$placeholder]) ? $this->blocks[$placeholder] : '';
    }
987453
public function renderBlock(BlockInterface $block, $arguments = array())
    {
        /** @var BlockManager $manager */
        $manager = $this->container->get('opifer.content.block_manager');

        $service = $manager->getService($block);

        if ($this->blockEnvironment->getBlockMode($block) == 'manage') {
            $content =  $service->setEnvironment($this->blockEnvironment)->manage($block)->getContent();
//            $block->isRendered = true;
//
//            // TODO check for unrendered blocks
//            if ($block instanceof BlockContainerInterface) {
//                foreach ($block->getChildren() as $child) {
//                    if (!property_exists($child, 'isRendered') || $child->isRendered) {
//                        $content .= $manager->getService($child)->manage($child)->getContent();
//                    }
//                }
//            }

            return $content;
        }

        return $service->execute($block)->getContent();
    }
1039201
public function render($name, array $context = [])
    {
        $renderedHtml = $this->twig->render($name, $context);

        foreach ($this->postProcessors as $postProcessor) {
            if ($postProcessor instanceof PostProcessorInterface) {
                $renderedHtml = $postProcessor->process($renderedHtml, $name, $context, $this->twig);
            }
        }

        return $renderedHtml;
    }
61454
public function renderParentBlock(OutputBuffer $out, $name)
	{
		$method = 'block_' . $name;

		if(method_exists($this, $method))
		{
			return $this->$method($out);
		}
		
		return parent::renderParentBlock($out, $name);
	}
1330334
public function renderResponse(BlockInterface $block, array $parameters = array(), Response $response = null)
    {
        $view = $this->getView($block);

        if ($response) {
            $this->setResponseHeaders($block, $response);
        }

        return $this->blockRenderer->render($view, $parameters, $response);
    }
963172
public function renderBlock($name, array $context, array $blocks = [], $useBlocks = true)
    {
        return $this->template->renderBlock($name, $context, $blocks, $useBlocks);
    }
359208
public function renderBlock(OutputBuffer $out, $name)
	{
		$method = 'block_' . $name;
		
		if(method_exists($this, $method))
		{
			$this->$method($out);
		}
		elseif($this->getParent() !== NULL)
		{
			$this->parent->renderBlock($out, $name);
		}
		else
		{
			throw new \RuntimeException(sprintf('Block not found: "%s"', $name));
		}
	}
893996
public function exists($name)
    {
        $viewblocks = $this->get('viewblocks', []);

        return !empty($viewblocks[$name]) || $this->Blocks->exists($name);
    }
420453
public function renderComponent($name, $parameters = [])
    {
        $result = null;
        $previousContext = $this->componentContext;

        if ($componentObj = $this->findComponentByName($name)) {
            $componentObj->id = uniqid($name);
            $componentObj->setProperties(array_merge($componentObj->getProperties(), $parameters));
            $this->componentContext = $componentObj;
            $result = $componentObj->onRender();
        }

        if (!$result) {
            $result = $this->renderPartial($name.'::default', [], false);
        }

        $this->componentContext = $previousContext;
        return $result;
    }
1324860
public function block($name, $default = null)
    {
        return isset($this->blocks[$name]) ? $this->blocks[$name] : $default;
    }
1276103
public function getRequestHeader($name)
    {
        return (isset($this->requestHeaders[$name])) ? $this->requestHeaders[$name] : null;
    }
440104
public function render($name, $data = null)
  {
    $t = $this->template($name, $data);

    return $t->render();
  }
756147
public function end($name)
    {
        $this->lastOpen = null;

        $this->opens[$name] = false;
        $last = array_pop($this->stacks);
        if ($last[0] != $name) {
            throw new BlockException($name, "is unexpected, expected {$last[0]}");
        }

        $content = ob_get_clean();
        if (!isset($this->hasChild[$name])) {
            $content = $this->_replace($content);
        }

        $pre = count($this->stacks) - 1;
        if ($pre > -1 && $this->opens[$this->stacks[$pre][0]]) {
            $this->hasChild[$this->stacks[$pre][0]] = true;
        }

        switch ($last[1]) {
            case 'replace' : // 默认
                break;
            case 'append' : // 追加
                $content = $this->parent($name) . $content;
                break;
            case 'prepend' : // 前面增加
                $content .= $this->parent($name);
                break;
            case 'hide' : // 不存在就隐藏
                if (!isset($this->blocks[$name])) {
                    $content = '';
                }
                break;
            default :
                throw new BlockException($name, 'undefined action type');
        }

        $this->blocks[$this->placeholder($name)] = $content;

        // 输出占位符
        if (isset($last[2])) {
            echo $last[2];
        }
    }