/** * {@inheritdoc} */ public function render($viewName, Model $model, NotificationCenter $notificationCenter, $output = true) { Profile::start('Renderer', 'Generate HTML'); $templateName = $viewName . '.' . static::$templateFileExtension; $dwoo = new Dwoo($this->compiledPath, $this->cachePath); $dwoo->getLoader()->addDirectory($this->functionsPath); Profile::start('Renderer', 'Create template file.'); $template = new Dwoo_Template_File($templateName); $template->setIncludePath($this->getTemplatesPath()); Profile::stop(); Profile::start('Renderer', 'Render'); $dwooData = new Dwoo_Data(); $dwooData->setData($model->getData()); $dwooData->assign('errorMessages', $notificationCenter->getErrors()); $dwooData->assign('successMessages', $notificationCenter->getSuccesses()); $this->setHeader('Content-type: text/html', $output); // I do never output directly from dwoo to have the possibility to show an error page if there was a render error. $result = $rendered = $dwoo->get($template, $dwooData, null, false); if ($output) { echo $result; } Profile::stop(); Profile::stop(); return $output ? null : $rendered; }
/** * {@inheritdoc} */ public function render($viewName, Model $model, NotificationCenter $notificationCenter, $output = true) { Profile::start('Renderer', 'Generate JSON'); if (strpos($viewName, 'errors/') === 0) { $data = array('error' => substr($viewName, strlen('errors/'))); } else { $c = $model->getData(Model::PUBLISHABLE); $data = array('content' => count($c) === 0 ? null : $c); } if (count($notificationCenter->getErrors())) { $data['errorMessages'] = $notificationCenter->getErrors(); } if (count($notificationCenter->getSuccesses())) { $data['successMessages'] = $notificationCenter->getSuccesses(); } $json = json_encode($data); $this->setHeader('Content-type: application/json', $output); if ($output) { echo $json; } Profile::stop(); return $output ? null : $json; }