Skip to content

Commit

Permalink
feat: add dedicated method loadLatte()
Browse files Browse the repository at this point in the history
  • Loading branch information
BernhardBaumrock committed May 10, 2023
1 parent 8f75d98 commit b0d1ac6
Showing 1 changed file with 20 additions and 15 deletions.
35 changes: 20 additions & 15 deletions RockFrontend.module.php
Expand Up @@ -1230,6 +1230,24 @@ public function loadAlfred(): bool
return $permission and $this->hasAlfred;
}

public function loadLatte()
{
if ($this->latte) return $this->latte;
try {
require_once __DIR__ . "/translate.php";
require_once $this->path . "vendor/autoload.php";
$latte = new Engine();
if ($this->wire->modules->isInstalled("TracyDebugger")) {
LattePanel::initialize($latte);
}
$latte->setTempDirectory($this->wire->config->paths->cache . "Latte");
return $this->latte = $latte;
} catch (\Throwable $th) {
$this->log($th->getMessage());
return false;
}
}

/**
* Create a site webmanifest in PW root
* @return Manifest
Expand Down Expand Up @@ -1569,21 +1587,8 @@ public function ___render($path, $vars = null, $options = [])
*/
protected function renderFileLatte($file, $vars)
{
$latte = $this->latte;
if (!$latte) {
try {
require_once __DIR__ . "/translate.php";
require_once $this->path . "vendor/autoload.php";
$latte = new Engine();
if ($this->modules->isInstalled("TracyDebugger")) {
LattePanel::initialize($latte);
}
$latte->setTempDirectory($this->wire->config->paths->cache . "Latte");
$this->latte = $latte;
} catch (\Throwable $th) {
return $th->getMessage();
}
}
$latte = $this->loadLatte();
if (!$latte) throw new WireException("Unable to load Latte");
return $latte->renderToString($file, $vars);
}

Expand Down

0 comments on commit b0d1ac6

Please sign in to comment.