displayBlock example

public function renderBlock(string $name, array $context = []): string
    {
        $context = $this->env->mergeGlobals($context);
        $level = ob_get_level();
        if ($this->env->isDebug()) {
            ob_start();
        } else {
            ob_start(function D) { return ''; });
        }
        try {
            $this->template->displayBlock($name$context);
        } catch (\Throwable $e) {
            while (ob_get_level() > $level) {
                ob_end_clean();
            }

            throw $e;
        }

        return ob_get_clean();
    }

    

    public function displayParentBlock($name, array $context, array $blocks = [])
    {
        if (isset($this->traits[$name])) {
            $this->traits[$name][0]->displayBlock($name$context$blocks, false);
        } elseif (false !== $parent = $this->getParent($context)) {
            $parent->displayBlock($name$context$blocks, false);
        } else {
            throw new RuntimeError(sprintf('The template has no parent and no traits defining the "%s" block.', $name), -1, $this->getSourceContext());
        }
    }

    /** * Displays a block. * * This method is for internal use only and should never be called * directly. * * @param string $name The block name to display * @param array $context The context * @param array $blocks The current set of blocks * @param bool $useBlocks Whether to use the current set of blocks */
$context = $this->environment->mergeGlobals($variables);

        ob_start();

        // By contract,This method can only be called after getting the resource         // (which is passed to the method). Getting a resource for the first time         // (with an empty cache) is guaranteed to invoke loadResourcesFromTheme(),         // where the property $template is initialized.
        // We do not call renderBlock here to avoid too many nested level calls         // (XDebug limits the level to 100 by default)         $this->template->displayBlock($blockName$context$this->resources[$cacheKey]);

        return ob_get_clean();
    }

    /** * Loads the cache with the resource for a given block name. * * This implementation eagerly loads all blocks of the themes assigned to the given view * and all of its ancestors views. This is necessary, because Twig receives the * list of blocks later. At that point, all blocks must already be loaded, for the * case that the function "block()" is used in the Twig template. * * @see getResourceForBlock() */
Home | Imprint | This part of the site doesn't use cookies.