venom = $venom; } public function render(): void { $isAsync = false; if ($this->controller) { ob_start(); $this->controller->render($this); $this->templateData = ob_get_clean(); $isAsync = $this->controller->getTemplate() === 'async'; } if ($isAsync || ArgumentHandler::get()->getItem('async', 'false') === 'true') { echo $this->templateData; exit; } $this->loadBasicTemplate(); } public function loadBasicTemplate(): void { if (file_exists($this->templateDir . $this->baseTemplate)) { include_once $this->templateDir . $this->baseTemplate; } else { echo 'Base Template not found...'; } } public function renderTemplate($template): void { // random variable name... to remove it instantly echo $this->includeTemplate($template, '1408138186'); unset($this->vars['1408138186']); } /** * function will load a template (without extension!) into a variable and return the content * @param $template * @param string $varName * @return false|string */ public function includeTemplate($template, $varName = '') { $template .= '.php'; if (file_exists($this->templateDir . $template)) { ob_start(); include_once $this->templateDir . $template; $data = ob_get_clean(); $this->vars[$varName] = $data; return $data; } $this->vars[$varName] = ''; return ''; } public function addVar($name, $value): void { $this->vars[$name] = $value; } public function getVar($name) { return $this->vars[$name]; } public function deleteVar($name): void { unset($this->vars[$name]); } public function init(?RenderController $controller): void { $this->controller = $controller; $data = Config::getInstance()->getRenderer(); $theme = $data->theme; $base = $data->baseFile ?? 'base'; $this->metaGenerator = new MetaGenerator(); if (Config::getInstance()->isAdmin()) { $base = 'base'; $theme = 'admin'; } else { $this->metaGenerator->loadById(); } $this->baseTemplate = $base . '.php'; $this->templateDir = __DIR__ . '/../../../tpl/' . $theme . '/'; } }