public function handle() { $action = $this->url->get("action", "default"); $whoops = new \Whoops\Run(); if ($this->url->get("ajax", false)) { $whoops->pushHandler(new \Whoops\Handler\JsonResponseHandler()); } else { $whoops->pushHandler(new \Whoops\Handler\PrettyPageHandler()); } $whoops->register(); $result = null; if (method_exists($this, "handle_" . $action)) { $result = call_user_func(array($this, "handle_" . $action)); } else { throw new Exception("Unknown action"); } $output = ""; if (is_string($result)) { $newResult = array('type' => 'transclude', 'content' => $result); $result = $newResult; } switch ($result['type']) { case "template": $output = $this->twig->renderTemplateToString($result['template'], $result['data']); break; case "json": $this->app->setJsonResponse(true); $data = $result['data']; $data['flashbag'] = FlashBag::getFlashes(); $output = json_encode($data); break; case "redirect": $this->app->_requestRedirect($result['url']); return; break; case "transclude": $pageMap = []; /** @var BasePage $pageItem */ foreach ($this->app->getPages() as $pageItem) { $pageMap[] = array('id' => $pageItem->getId(), 'name' => $pageItem->getName()); } ValueBag::set("flashbag", FlashBag::getFlashes()); $data = array('valueBag' => json_encode(ValueBag::getValues()), 'staticRoot' => $this->app->getStaticRoot(), 'pageMap' => $pageMap, 'defaultUrl' => $this->routeGen->defaultRoute(), 'title' => $this->app->getAppName(), 'userParams' => $this->app->getUserParams(), 'pageTitle' => ''); if ($this->page !== null) { $data['page'] = $this->page; $data['currentId'] = $this->page->getId(); $data['pageTitle'] = $this->page->getName(); } else { $data['currentId'] = -1; } $data['page_content'] = $result['content']; $data['dev'] = false; // change to true to load unminified js $output = $this->twig->renderTemplateToString("main_page.twig", $data); break; default: throw new Exception("Unknown result type"); } return $output; }
public function renderInline() { $twig = new TwigUtil(); $this->params['formItems'] = $this->formItems; // $this->params['id'] = $this->id; // ValueBag::set($this->id, $this->jsParams); return $twig->renderTemplateToString("util/form_inline.twig", $this->params); }
public function handle_new_item() { $twig = new TwigUtil(); $form = $this->dataProvider->getEditForm(); $form->setPageId($this->getId()); $form->setNewItem(); $formContent = $form->render($this->dataProvider->getEditFormOrder()); $templateData = array('page' => $this, 'name' => $this->name, 'editForm' => $formContent); return $twig->renderTemplateToString("pages/basicdata/edit_item.twig", $templateData); }
function render() { $twig = new TwigUtil(); return $twig->renderTemplateToString("pages/dummy.twig", array('name' => $this->name, 'content' => $this->content)); }