/**
  * Register Knit Component
  * @throws BootstrapException
  */
 protected function registerKnit()
 {
     // Container has Knit component, must be defined in config
     if (!property_exists($this->config->app, "knit")) {
         throw BootstrapException::knitNode();
     }
     // Bootstrap knit
     $this->knit = $this->container->get("Knit");
     // Compiler path
     if (!property_exists($this->config->app->knit, "compilerPath")) {
         throw BootstrapException::knitCompilerPath();
     }
     try {
         $this->knit->setCompilerPath($this->rootPath . self::DS . $this->config->app->knit->compilerPath);
         // Caching
         if (property_exists($this->config->app->knit, "caching")) {
             /** @var $this Kernel */
             switch ($this->config->app->knit->caching) {
                 case "static":
                 case 1:
                     $this->knit->setCachePath($this->getDisk("cache"))->setCaching(Knit::CACHE_STATIC);
                     break;
                 case "dynamic":
                 case 2:
                     $this->knit->setCachePath($this->getDisk("cache"))->setCaching(Knit::CACHE_DYNAMIC);
                     break;
             }
         }
     } catch (\ComelyException $e) {
         throw new BootstrapException(__METHOD__, $e->getMessage(), $e->getCode());
     }
 }
 /**
  * @param Knit $knit
  * @param string $tpl
  * @param string $param
  * @throws \Comely\Framework\KernelException
  */
 public function knit(Knit $knit, string $tpl, string $param = "body")
 {
     // Get CSRF token
     $csrfToken = $this->app->security()->csrf()->getToken();
     if (!$csrfToken) {
         // Set new CSRF token as it is not already set
         $csrfToken = $this->app->security()->csrf()->setToken();
     }
     // Set "csrfToken" prop in Page object
     $this->page->setProp("csrfToken", $csrfToken);
     // Assign variables to Knit
     $knit->assign("errors", $this->app->errorHandler()->fetchAll());
     $knit->assign("page", $this->page->getArray());
     $knit->assign("config", ["site" => $this->app->config()->getNode("site")]);
     // Prepare template and set in Response object
     $template = $knit->prepare($tpl);
     $this->response->set($param, $template->getOutput());
 }