Airship\Engine\Lens::render PHP Method

render() public method

Render a template and return its contents as a string.
public render ( string $base, array $params = [] ) : string
$base string Template to render (e.g. 'index' or 'dir/index')
$params array Parameters to pass towards the array
return string
    public function render(string $base, array $params = []) : string
    {
        return $this->twigEnv->render($base . '.twig', \array_merge($this->stored, $params));
    }

Usage Example

Example #1
0
 /**
  * Render lens content, cache it, then display it.
  *
  * @param string $name
  * @param array $cArgs Constructor arguments
  * @return bool
  * @exit;
  */
 protected function stasis(string $name, ...$cArgs) : bool
 {
     // We don't want to cache anything tied to a session.
     $oldSession = $_SESSION;
     $_SESSION = [];
     $data = $this->airship_lens_object->render($name, ...$cArgs);
     $_SESSION = $oldSession;
     $port = $_SERVER['HTTP_PORT'] ?? '';
     $cacheKey = $_SERVER['HTTP_HOST'] . ':' . $port . '/' . $_SERVER['REQUEST_URI'];
     if (!$this->airship_filecache_object->set($cacheKey, $data)) {
         return false;
     }
     $state = State::instance();
     if (!\headers_sent()) {
         \header('Content-Type: text/html;charset=UTF-8');
         \header('Content-Language: ' . $state->lang);
         \header('X-Content-Type-Options: nosniff');
         \header('X-Frame-Options: SAMEORIGIN');
         // Maybe make this configurable down the line?
         \header('X-XSS-Protection: 1; mode=block');
         $hpkp = $state->HPKP;
         if ($hpkp instanceof HPKPBuilder) {
             $hpkp->sendHPKPHeader();
         }
         $csp = $state->CSP;
         if ($csp instanceof CSPBuilder) {
             $csp->sendCSPHeader();
             $this->airship_cspcache_object->set($_SERVER['REQUEST_URI'], \json_encode($csp->getHeaderArray()));
         }
     }
     die($data);
 }