2015-08-13
@used-by \Df\Framework\Plugin\View\TemplateEngineInterface::aroundRender()
@param BlockInterface|null $block
@param string|null $templateFile
553545
function blockSet(BlockInterface $block, $templateFile) {
		$this->_blockStack[]= $block;
		$this->_templateFileStack[]= $templateFile;
	}
482332
protected function display($templateFile='',$charset='',$contentType='',$content='',$prefix='') {
        $this->view->display($templateFile,$charset,$contentType,$content,$prefix);
    }
116678
def _render_template_block_nodelist(nodelist, block_name, context):
    """"""

    # Attempt to find the wanted block in the current template.
    for node in nodelist:
        # If the wanted block was found, return it.
        if isinstance(node, BlockNode):
            # No matter what, add this block to the rendering context.
            context.render_context[BLOCK_CONTEXT_KEY].push(node.name, node)

            # If the name matches, you're all set and we found the block!
            if node.name == block_name:
                return node.render(context)

        # If a node has children, recurse into them. Based on
        # django.template.base.Node.get_nodes_by_type.
        for attr in node.child_nodelists:
            try:
                new_nodelist = getattr(node, attr)
            except AttributeError:
                continue

            # Try to find the block recursively.
            try:
                return _render_template_block_nodelist(new_nodelist, block_name, context)
            except BlockNotFound:
                continue

    # The wanted block_name was not found.
    raise BlockNotFound("block with name '%s' does not exist" % block_name)
1071365
public function render(string $templateFile = '')
    {
        if ($templateFile) {
            $this->setTemplateFile($templateFile);
        }

        $this->initRender();


        try {
            ob_start();
            include $this->getTemplateFile();
            $this->content = ob_get_clean();
        } catch (\Exception $e) {
            ob_end_clean();
            throw new ViewException($e->getMessage(), $e->getCode());
        }

        return $this->content;
    }
567011
public function updateBlock(Block $block): void
    {
        $query = $this->connection->createQueryBuilder();
        $query
            ->update('ngbm_block')
            ->set('layout_id', ':layout_id')
            ->set('depth', ':depth')
            ->set('path', ':path')
            ->set('parent_id', ':parent_id')
            ->set('placeholder', ':placeholder')
            ->set('position', ':position')
            ->set('definition_identifier', ':definition_identifier')
            ->set('view_type', ':view_type')
            ->set('item_view_type', ':item_view_type')
            ->set('name', ':name')
            ->set('translatable', ':translatable')
            ->set('main_locale', ':main_locale')
            ->set('always_available', ':always_available')
            ->set('config', ':config')
            ->where(
                $query->expr()->eq('id', ':id')
            )
            ->setParameter('id', $block->id, Type::INTEGER)
            ->setParameter('layout_id', $block->layoutId, Type::INTEGER)
            ->setParameter('depth', $block->depth, Type::STRING)
            ->setParameter('path', $block->path, Type::STRING)
            ->setParameter('parent_id', $block->parentId, Type::INTEGER)
            ->setParameter('placeholder', $block->placeholder, Type::STRING)
            ->setParameter('position', $block->position, Type::INTEGER)
            ->setParameter('definition_identifier', $block->definitionIdentifier, Type::STRING)
            ->setParameter('view_type', $block->viewType, Type::STRING)
            ->setParameter('item_view_type', $block->itemViewType, Type::STRING)
            ->setParameter('name', $block->name, Type::STRING)
            ->setParameter('translatable', $block->isTranslatable, Type::BOOLEAN)
            ->setParameter('main_locale', $block->mainLocale, Type::STRING)
            ->setParameter('always_available', $block->alwaysAvailable, Type::BOOLEAN)
            ->setParameter('config', $block->config, Type::JSON_ARRAY);

        $this->applyStatusCondition($query, $block->status);

        $query->execute();
    }
595706
protected function _afterRender(TemplateContextInterface $context)
    {
        if(is_string($context->result))
        {
            $content = $context->result;

            foreach($this->__filter_queue as $filter) {
                $filter->filter($content, $this->getMixer());
            }

            $context->result = $content;
        }
    }
963172
public function renderBlock($name, array $context, array $blocks = [], $useBlocks = true)
    {
        return $this->template->renderBlock($name, $context, $blocks, $useBlocks);
    }
951676
public function renderBlock(string $blockName): string
    {
        if (!$this->template->hasBlock($blockName, $this->context, $this->blocks)) {
            return '';
        }

        $level = ob_get_level();
        ob_start();

        try {
            $this->template->displayBlock($blockName, $this->context, $this->blocks);
        } catch (Throwable $t) {
            while (ob_get_level() > $level) {
                ob_end_clean();
            }

            throw $t;
        }

        return (string) ob_get_clean();
    }
1205526
private function renderPage($layoutFile = null, $params = null)
    {
        $this->setNode($this->getObject());

        $application = $this->getApplication();
        // Rendering subcontent
        if (null !== $contentSet = $this->getObject()->getContentSet()) {
            $bbUserToken = $application->getBBUserToken();
            $revisionRepo = $application->getEntityManager()->getRepository('BackBee\ClassContent\Revision');
            if (null !== $bbUserToken && null !== $revision = $revisionRepo->getDraft($contentSet, $bbUserToken)) {
                $contentSet->setDraft($revision);
            }

            $layout = $this->getObject()->getLayout();
            $zones = $layout->getZones();
            $zoneIndex = 0;

            foreach ($contentSet->getData() as $content) {
                if (array_key_exists($zoneIndex, $zones)) {
                    $zone = $zones[$zoneIndex];
                    $isMain = null !== $zone && property_exists($zone, 'mainZone') && true === $zone->mainZone;
                    $this->container()->add($this->render($content, $this->getMode(), array(
                        'class' => 'rootContentSet',
                        'isRoot' => true,
                        'indexZone' => $zoneIndex++,
                        'isMainZone' => $isMain,
                    ), null, $this->_ignoreIfRenderModeNotAvailable));
                }
            }
        }

        // Check for a valid layout file
        $this->templateFile = $layoutFile;
        if (null === $this->templateFile) {
            $this->templateFile = $this->getLayoutFile($this->getCurrentPage()->getLayout());
        }

        if (!$this->isValidTemplateFile($this->templateFile, true)) {
            throw new RendererException(
                sprintf('Unable to read layout %s.', $this->templateFile), RendererException::LAYOUT_ERROR
            );
        }

        $application->info(sprintf('Rendering page `%s`.', $this->getObject()->getNormalizeUri()));

        return $this->renderTemplate(false, true);
    }
116952
public function beforeRender($event, $viewFile)
    {
        if(Configure::read('Altair.escape')) {
            $event->getSubject()->viewVars = $this->automate($event->getSubject()->viewVars);
        }
    }
1103843
public function draw()
    {
        $file = Application::current()->getDirectory();
        $file .= "views/{$this->templateName}.";
        $file .= self::$extension;

        if (!file_exists($file)) {
            throw new Exception("Template file not found: $file");
        }

        return $this->templateEngine->draw(
            $file, $this->data
        );
    }
838976
public function renderTemplate($templatePath = null, $data = [])
    {
        $templateData = $this->readTemplate($templatePath);
        if($data === null) {
            throw new Exception("template(): expects parameter 2 to be array, null given");
        }
        foreach($data as $key => $val) {
            if(is_array($val)) {
                $findStart = strpos($templateData, '{{'.$key.':}}');
                if($findStart !== false) {
                    $findEnd = strpos($templateData, '{{:'.$key.'}}');
                    if($findEnd !== false) {
                        $len = 5 + strlen($key);
                        $substr = substr($templateData, $findStart, ($findEnd - $findStart));
                        $substr = substr($substr, $len);
                        $loopstr = []; #fixed-for: Uncaught Error: [] operator not supported for strings $loopstr[]
                        foreach($val as $k => $v) {
                            $temp = $substr;
                            if(is_array($v)) {
                                //$temp = strtr($temp, $v); {{}} not replaced
                                foreach($v as $ks => $vs) {
                                    $temp = str_replace('{{'.$ks.'}}', $vs, $temp);
                                }
                            }
                            else {
                                $temp = str_replace('{{'.$key.'}}', $v, $temp);
                            }
                            $loopstr[] = $temp;
                        }
                        $loopstr = implode("\n", $loopstr);
                        $templateData = str_replace('{{'.$key.':}}'.$substr.'{{:'.$key.'}}', $loopstr, $templateData);
                    }
                    else {
                        throw new Exception('Error in template : loop has not closed properely');
                        exit;
                    }
                }
            }
            else {
                $templateData = str_replace('{{'.$key.'}}', $val, $templateData);
            }
        }
        return $templateData;
    }
1334678
public function render(AbstractBlock $block, CliRenderer $renderer)
    {
        if (!($block instanceof FencedCode)) {
            throw new \InvalidArgumentException(sprintf('Incompatible block type: "%s"', get_class($block)));
        }

        $infoWords = $block->getInfoWords();
        $codeType = null;
        if (count($infoWords) !== 0 && strlen($infoWords[0]) !== 0) {
            $codeType = $infoWords[0];
        }

        if (null === $codeType || !isset($this->highlighters[$codeType])) {
            return $this->indent($renderer->style($block->getStringContent(), 'yellow'));
        }

        return $this->indent(
            sprintf("%s\n", $this->highlighters[$codeType]->highlight($block->getStringContent()))
        );
    }
575785
public function render(AbstractBlock $block, CliRenderer $renderer)
    {
        if (!($block instanceof ThematicBreak)) {
            throw new \InvalidArgumentException(sprintf('Incompatible block type: "%s"', get_class($block)));
        }

        return $renderer->style(str_repeat('-', $this->width), 'dark_gray');
    }
1372952
public function getBlockFromTemplate($twig, $template, $block, $vars = [])
    {
        return $twig
            ->loadTemplate($template)
            ->renderBlock($block, $vars)
        ;
    }
149478
public function execute(BlockContextInterface $blockContext, Response $response = null)
    {
        /** @var BlockDocument $block */
        $block = $blockContext->getBlock();
        $this->formService->processBlock($block);
        $template = $block->getTemplate();
        if (is_null($template)) {
            throw new MissingBlockTemplateException("Template must be defined on for block " . $block->getName());
        }
        return $this->getTemplating()->renderResponse($template->getName(), $block->getViewVariables()->toArray());
    }
1267502
public static function Render($template=null, $data=null)
    {
        if ($template && $data) {
            return self::$renderer->render($template, $data);
        } else {
            self::$data = self::getData();
            self::$templates[] = "index";
            self::loadTemplate(self::$templates);
        }
    }