/** * Вызов блока * @param string $path Внутренний путь до блока * @param string $template Шаблон блока * @param array $params Параметры, передаваемые блоку * @throws \T4\Core\Exception * @return string Результат рендера блока */ public function callBlock($path, $template = '', $params = []) { $route = new Route($path); $route->params->merge($params); $canonicalPath = $route->toString(); if (isset($this->config->blocks) && isset($this->config->blocks[$canonicalPath])) { $blockOptions = $this->config->blocks[$canonicalPath]; } else { $blockOptions = []; } $getBlock = function () use($template, $route) { $controller = $this->createController($route->module, $route->controller); $controller->action($route->action, $route->params); return $controller->view->render($route->action . (!empty($template) ? '.' . $template : '') . '.block.html', $controller->getData()); }; if (!empty($blockOptions['cache'])) { $cache = \T4\Cache\Factory::getInstance(); $key = md5($canonicalPath . serialize($route->params) . $template); if (!empty($blockOptions['cache']['time'])) { return $cache($key, $getBlock, $blockOptions['cache']['time']); } else { return $cache($key, $getBlock); } } else { return $getBlock(); } }