Back to HtmlDocument class

Method getBuffer

public mixed|string
getBuffer
(mixed $type = null, mixed $name = null, mixed $attribs = array())
Get the contents of a document include
Parameters
  • string $type The type of renderer
  • string $name The name of the element to render
  • array $attribs Associative array of remaining attributes.
Returns
  • mixed|string The output of the renderer
Since
  • 1.7.0
Class: HtmlDocument
Project: Joomla

Method getBuffer - Source code

/**
 * Get the contents of a document include
 *
 * @param   string  $type     The type of renderer
 * @param   string  $name     The name of the element to render
 * @param   array   $attribs  Associative array of remaining attributes.
 *
 * @return  mixed|string The output of the renderer
 *
 * @since   1.7.0
 */
public function getBuffer($type = null, $name = null, $attribs = array())
{
    // If no type is specified, return the whole buffer
    if ($type === null) {
        return parent::$_buffer;
    }
    $title = $attribs['title'] ?? null;
    if (isset(parent::$_buffer[$type][$name][$title])) {
        return parent::$_buffer[$type][$name][$title];
    }
    $renderer = $this->loadRenderer($type);
    if ($this->_caching == true && $type === 'modules' && $name !== 'debug') {
        /** @var  \Joomla\CMS\Document\Renderer\Html\ModulesRenderer  $renderer */
        /** @var  \Joomla\CMS\Cache\Controller\OutputController  $cache */
        $cache = CmsFactory::getContainer()->get(CacheControllerFactoryInterface::class)->createCacheController('output', ['defaultgroup' => 'com_modules']);
        $itemId = (int) CmsFactory::getApplication()->input->get('Itemid', 0, 'int');
        $hash = md5(serialize([$name, $attribs, \get_class($renderer), $itemId]));
        $cbuffer = $cache->get('cbuffer_' . $type);
        if (isset($cbuffer[$hash])) {
            return Cache::getWorkarounds($cbuffer[$hash], array('mergehead' => 1));
        }
        $options = array();
        $options['nopathway'] = 1;
        $options['nomodules'] = 1;
        $options['modulemode'] = 1;
        $this->setBuffer($renderer->render($name, $attribs, null), $type, $name);
        $data = parent::$_buffer[$type][$name][$title];
        $tmpdata = Cache::setWorkarounds($data, $options);
        $cbuffer[$hash] = $tmpdata;
        $cache->store($cbuffer, 'cbuffer_' . $type);
    } else {
        $this->setBuffer($renderer->render($name, $attribs, null), $type, $name, $title);
    }
    return parent::$_buffer[$type][$name][$title];
}