/** * Handler. * * @param ServerRequestInterface $request * @param ResponseInterface $response * * @return ResponseInterface */ public function __invoke(ServerRequestInterface $request, ResponseInterface $response) { $page = $request->getAttribute('page', '/index'); $content = $this->contentLoader->getContent($page); $template = $content->getMetadataEntry('template'); $params = array_merge($content->getMetadata(), ['html' => $content->getHtml()]); $response->getBody()->write($this->plates->render($template, $params)); return $response->withHeader('Content-Type', 'text/html'); }
/** * @param $template * @return bool */ public function __invoke($template) { // $template = $this->getPlatesPath($template); // get the HTML for whatever is going on echo $this->engine->render($template); // because we echo'd already, we return false so it's not double-echo'd by wordpress' // default `include $template` statement return false; }
/** * @param BatchManager $batches * @param ServerRequestInterface $request * @param string $task * * @return View */ public function index(BatchManager $batches, ServerRequestInterface $request, $task = 'custom') { // Interactive mode $query = $request->getQueryParams(); if (array_key_exists('interactive', $query)) { $this->configuration['tasks'] = $query['interactive']; } $task = $this->getTask($task); $sync = array_get($query, 'sync'); $method = $sync ? 'runTask' : 'getCommandsFrom'; $commands = $this->runner->{$method}($task); // Store commands for retrieval $hash = $batches->set($commands); return $this->views->render('index', ['tasks' => $commands, 'hash' => $hash, 'url' => $this->configuration->get('url')]); }
public function __invoke(array $input) { $name = 'index'; if (!empty($input['name'])) { $name = $input['name']; } // $filename = APPPATH . 'templates/static/' . $name; // if (file_exists($filename)) { // echo "The file $filename does not exist"; // die('the file does not exist'); // } // Create new Plates instance $plates = new Engine(APPPATH . 'templates'); // Register extension $plates->loadExtension(new Utils()); // Check static page or partial exists if ($plates->exists('static/' . $name)) { // Render a template $template = $plates->render('static/' . $name); } else { header("HTTP/1.0 404 Not Found"); echo "PHP continues.\n"; echo "Not after a die, however.\n"; die; } // return return (new Payload())->withStatus(Payload::OK)->withOutput(['hello' => $template]); }
/** * Render the template. * * @param string $name * @param string[] $data * * @throws \LogicException * * @return \Psr\Http\Message\ResponseInterface */ public function render($name, array $data = []) { if (!isset($this->response)) { throw new \LogicException(sprintf('Invalid %s object instance', ResponseInterface::class)); } return $this->response->write($this->plates->render($name, $data)); }
/** * Render a string * * @param string $template The template content to render * @param array $locals The variable to use in template * @return null|string */ public function render($template, array $locals = array()) { $tmpName = uniqid('plates_tmp_', false); $tmpPath = sys_get_temp_dir() . DIRECTORY_SEPARATOR . $tmpName; if (!is_null($this->plates->getFileExtension())) { $tmpPath .= '.' . $this->plates->getFileExtension(); } $isTmpRegister = $this->plates->getFolders()->exists(sys_get_temp_dir()); if (!$isTmpRegister) { $this->plates->addFolder(sys_get_temp_dir(), sys_get_temp_dir()); } file_put_contents($tmpPath, $template); $data = $this->plates->render(sys_get_temp_dir() . '::' . $tmpName, $locals); unlink($tmpPath); if (!$isTmpRegister) { $this->plates->getFolders()->remove(sys_get_temp_dir()); } return $data; }
public function render($name, $data = [], $echo = false) { $data["layoutName"] = $this->getLayoutName(); $data["crud"] = $this; $html = $this->template->render($name, $data); if ($echo) { echo $html; } return $html; }
protected function render($name) { if (!count($this->templateVars)) { return $this->templater->render($name); } $vars = []; foreach ($this->templateVars as $var) { $vars = array_merge($vars, $var); } return $this->templater->render($name, $vars); }
/** * @param string $type * @return string */ public function render($type = null) { $templates = new Engine($this->viewPath); if ($type === null) { if ($this->media === false) { $type = 'media'; } else { $type = 'thumbnail'; } } return $templates->render($type, $this->toArray()); }
public function __invoke(array $input) { $name = 'world'; if (!empty($input['name'])) { $name = $input['name']; } //////////////////// $application = new Application(); $application_data = $application->is_pjax(); //print_r( '<pre>' ); // print_r( $application_data ); //print_r( '</pre>'); //////////////////// // simple // Create new Plates instance // $plates = new Engine(APPPATH.'templates'); // Render a template // $template = $plates->render('partials/profile', ['name' => $name . ' | ' . $data_from_an_other_class]); // $template = $plates->render('partials/profile', ['name' => $name . ' | ' . $application_data]); $data = ['friends' => ['mikka', 'makka', 'zorro']]; // $friends = [ // ['name', 'zorro'], // ]; //////////////////// // using folders // Create new Plates instance $plates = new Engine(APPPATH . 'templates'); // Register a Plates extension $plates->loadExtension(new Utils()); // Add folders $plates->addFolder('layout', APPPATH . 'templates'); $plates->addFolder('partials', APPPATH . 'templates/partials'); $plates->addFolder('static', APPPATH . 'templates/static'); // assign data to plates $plates->addData($data, 'layout'); // Render $template = $plates->render('partials::profile', ['name' => $name]); //////////////////// $invitation = 'I invite you'; // return return (new Payload())->withStatus(Payload::OK)->withOutput(['hello' => $template, 'invitation' => $invitation]); }
public function testRender() { $this->assertSame($this->engine->render('simple'), $this->strategy->render('simple')); }
/** * Output a rendered template. * @param string $name * @param array $data * @return null */ protected function insert($name, array $data = array()) { echo $this->engine->render($name, $data); }
/** * @param PayloadInterface $payload * * @return string */ private function render(PayloadInterface $payload) { $template = $payload->getSetting('template'); $output = $payload->getOutput(); return $this->engine->render($template, $output); }
/** * Render a plate template and return with a PSR-7 Response object. * * @param ResponseInterface $response * @param $template * @param array $data * * @return ResponseInterface */ public function render(ResponseInterface $response, $template, array $data = []) { $response->getBody()->write($this->engine->render($template, $data)); return $response; }
/** * Evaluates the template with its variables. * * @param string $template The template relative path * @param array $vars The template variables * * @return string */ public function evaluate($template, array $vars = []) { $reference = $this->loadTemplate($template, $vars); return $this->plates->render($template, $reference->getVariables()); }
/** * Render * * @param string $name * @param array|object $params * @return string */ public function render($name, $params = []) { $params = $this->normalizeParams($params); return $this->template->render($name, $params); }
/** * {@inheritdoc} */ public function render($template, $params) : string { $this->engine->render($template, $params); }
public function renderNotice($template = 'notice') { return $this->engine->render($template, array('notices' => $this->getNotices())); }
/** * @return int|null A handler may return nothing, or a Handler::HANDLE_* constant */ public function handle() { echo $this->templates->render('error', ['exception' => $this->getException()]); }
/** * Create a new template and render it. * * @param string $name * @param array $data * @return string */ public function render($name, array $data = []) { return $this->engine->render($name, $data); }
/** * Render the template * * @param \Psr\Http\Message\ResponseInterface $response * @param string $name * @param string[] $data * @return \Psr\Http\Message\ResponseInterface */ public function render(ResponseInterface $response, $name, array $data = []) { return $response->getBody()->write($this->plates->render($name, $data)); }
/** * {@inheritDoc} */ public function render($template, array $params = []) { return $this->engine->render($template, $params); }
/** * setup the template engine and sends the parsed content to the engine * * @uses \League\Plates\Extension\Asset * @uses \League\Plates\Engine * @uses url * @since 1.0 */ public function setup() { $engine = new Engine($this->relativePath . "include" . DS . "styles" . DS . config::init()->style); $engine->loadExtension(new Asset($this->relativePath . "include" . DS . "styles" . DS . config::init()->style . DS . "assets", true)); // add infos for theme $this->setStyleParameter("isZipEnabled", false); $this->setStyleParameter("showWarnings", false); $breadcrumbs = $this->generateBreadcrumbs(url::GET("dir")); $this->setStyleParameter("breadcrumbs", $breadcrumbs); $this->setStyleParameter("assetspath", common::getRelativePath(getcwd(), dirname(__FILE__)) . DS . "styles" . DS . config::init()->style . DS . "assets"); $this->setStyleParameter("title", "SimpleDirLister | " . common::fixPaths(implode(DS, array_keys($breadcrumbs)))); $this->setStyleParameter("path", common::fixPaths(implode(DS, array_keys($breadcrumbs)))); $this->setStyleParameter("header", config::init()->header ? file::init(config::init()->header)->getFilename() : false); $this->setStyleParameter("footer", config::init()->footer ? file::init(config::init()->footer)->getFilename() : false); $engine->addFolder('static', $this->getBasePath() . DS . config::init()->headerFooterDir); try { $files = $this->getRawPaths(); $files = $this->cleanArray($files); if (config::init()->showReadme) { $readmeContent = []; foreach (config::init()->readme as $readme) { if (isset($files[$readme])) { $c = file_get_contents($files[$readme]["path"]); $ext = pathinfo($files[$readme]["path"], PATHINFO_EXTENSION); if ($ext == "md") { $md = new Parsedown(); $readmeContent[] = '<div class="md">' . $md->text($c) . '</div>'; } elseif ($ext == "php") { $readmeContent[] = (require $files[$readme]["path"]); } else { $readmeContent[] = $c; } if (config::init()->removeReadme) { unset($files[$readme]); } } } $this->setStyleParameter("readme", $readmeContent); } } catch (\Exception $e) { $this->setStyleParameter("showWarnings", true); $this->setStyleParameter("warnings", [["message" => "dir not found", "type" => "danger"]]); $files = []; } finally { $this->setStyleParameter("files", $files); } $engine->registerFunction('fileicon', [&$this, "getIconFromSet"]); $this->setStyleParameter("search", url::GET("s")); $engine->addData($this->styleParameter); if (!empty(url::GET("s"))) { echo $engine->render("search", $this->styleParameter); } else { echo $engine->render("index", $this->styleParameter); } }
public function view($view, $data = []) { $templates = new Engine(__DIR__ . '/../../views'); return $templates->render($view, $data); }
/** * @param $view * @param null $data */ public function render($view, $data = NULL) { echo $this->minify($data !== NULL ? $this->template->render($view, $data) : $this->template->render($view)); }
/** * @param ResponseInterface $response * @param TemplateResult $templateResult * @return ResponseInterface */ private function modifyResponseForTemplateResult(ResponseInterface $response, TemplateResult $templateResult) { $this->engine->addData(['host' => 'http://' . $this->serverRequest->getServerParams()['HTTP_HOST'] . '/']); $stream = \GuzzleHttp\Psr7\stream_for($this->engine->render($templateResult->getTemplate(), $templateResult->getData())); return $response->withHeader('Content-Type', 'text/html')->withBody($stream); }
public function showLogin(Engine $templates) { // If it is a request with invalid token just return "false" so that we can catch this $token = $this->request->header('Authorization') !== null ? $this->request->header('Authorization') : ''; if ($token !== '') { return 'false'; } $content = $templates->render('partials/login', ['title' => 'Login Required']); return $content; }