public function __construct() { $this->config = DI::get('Config'); $tags = $this->config->get('plugins.config.shortcode', []); $this->shortcode = new Shortcode($tags); DI::set('Shortcode', $this->shortcode); }
protected function addBlocksTag() { $this->add('blocks', function ($options) { $options = array_merge(['path' => DI::get('Page')->getDefaultBlocksPath(), 'sort' => '', 'shuffle' => 'false'], (array) $options); // collect pages $extensions = $this->config->get('pages.extensions', []); $path = $options['path']; $paths = [$path => DI::get('Alias')->get($path)]; $pageBuilder = new Herbie\Menu\Page\Builder($paths, $extensions); $collection = $pageBuilder->buildCollection(); if (!empty($options['sort'])) { list($field, $direction) = explode('|', $options['sort']); $collection = $collection->sort($field, $direction); } if ('true' == strtolower($options['shuffle'])) { $collection = $collection->shuffle(); } $twig = DI::get('Twig'); // store page $page = DI::get('Page'); $return = ''; foreach ($collection as $i => $item) { $block = Herbie\Page::create($item->path); DI::set('Page', $block); // self-contained blocks aka widgets if (!empty($block->layout) && file_exists($paths[$path] . '/.layouts/' . $block->layout)) { $block->layout = $path . '/.layouts/' . $block->layout; } if (empty($block->layout)) { $return .= $twig->renderPageSegment(0, $block); } else { $twig->getEnvironment()->getExtension('herbie')->setPage($block); $return .= $twig->render($block->layout, ['block' => $block]); } $return .= "\n"; } // restore page $twig->getEnvironment()->getExtension('herbie')->setPage($page); DI::set('Page', $page); return trim($return); }); }