true, # шаблон для админ. панели * 'query' => ['key'=>'value', ...] * ] * @return void */ public function codingTemplateAdd( string $title, string $template, $admin = true, array $query = [], array $opts = [] ) { if (is_array($admin)) { $opts = $this->defaults($opts, [ 'admin' => true, 'query' => $query, ]); $opts = array_merge($opts, $admin); } else { $opts['admin'] = $admin; $opts['query'] = $query; } $this->plugin_coding_templates[] = [ 'title' => $title, 'template' => $template, 'admin' => !empty($opts['admin']), 'opts' => $opts, ]; } /** * Формируем ссылку на файл шаблона * @param string $template название файла php шаблона (file.php, /dir/file.php) * @param array $query параметры ссылки * @param bool $admin шаблон для админ. панели * @return string */ public function codingTemplateUrl(string $template, array $query = [], bool $admin = true): string { $query['template'] = $template; return $this->urlAction('codingTemplateView', ['query' => $query], !empty($admin)); } /** * Просматриваем шаблон страницы * @param string|bool|CodingTemplate $template путь к файлу шаблона * @param array $data данные передаваемые в шаблон * @return string HTML */ public function codingTemplateView($template = false, array $data = []): string { if (empty($template)) { $template = $this->input->get('template', TYPE_NOTAGS); $isGet = true; } if (! empty($template)) { if (is_string($template)) { $template = new CodingTemplate($template, $this); } if (is_object($template)) { return $this->codingTemplateRender($template, $data); } } if (isset($isGet)) { $this->errors->impossible(); } return ''; } /** * Отрисовка шаблона страницы верстки * @param CodingTemplate $template объект шаблона * @param array $data данные передаваемые в шаблон * @return string|mixed HTML */ public function codingTemplateRender($template, array $data = []) { if (empty($template)) { return ''; } $path = $template->getPath(); $path = trim($path, '/' . DS); if (mb_stripos($path, $this->plugin_templates_dir . DS) !== 0) { $path = $this->plugin_templates_dir . DS . $path; } if (mb_substr($path, -4) === '.php') { $path = mb_substr($path, 0, mb_strlen($path) - 4); } return $this->template($path, $data, ['this' => $template]); } /** * Получаем список шаблонов * @return array */ public function codingTemplatesList(): array { return $this->plugin_coding_templates; } }