/** * Render With * @param string $templateFile - Template file location * @return string - Parsed template contents */ public function renderWith($templateFile) { if (is_array($templateFile)) { $templateFile = call_user_func_array("Touchbase\\Filesystem\\Filesystem::buildPath", $templateFile); } foreach ($this->controller->templateSearchPaths() as $path) { $templateFileObj = File::create([$path, $templateFile]); if ($templateFileObj->exists()) { $templateFilePath = $templateFileObj->path; break; } } if (!isset($templateFilePath)) { return false; } $this->assign("controller", $this->controller); $this->assign("request", $this->controller->request()); $this->assign("errors", $this->controller->errors); $this->assign("messages", $this->controller->messages); //TODO: Sort this out! if (isset($this->controller) && $this->controller instanceof \Touchbase\Control\WebpageController) { $this->assign("assets", $this->controller->response()->assets()); } if ($template = $this->readTemplate($templateFilePath)) { /** * Auto CSS / JS include */ if (isset($this->controller) && $this->controller instanceof \Touchbase\Control\WebpageController) { //Include Template Styles $fileParts = pathinfo($templateFilePath); $templateName = strtolower(basename($fileParts['filename'], ".tpl")); //Make sure to only add styles for our phtml templates if ($fileParts['extension'] === "php") { $this->controller->response()->assets()->includeStyle($templateName . ".css"); $this->controller->response()->assets()->includeScript($templateName . ".js"); //Include Controller Sytles $controllerName = strtolower($this->controller->controllerName); $this->controller->response()->assets()->includeStyle($controllerName . ".css"); $this->controller->response()->assets()->includeScript($controllerName . ".js"); } } return $template; } return false; }