Files
Jump/jumpapp/classes/Pages/AbstractPage.php

57 lines
1.7 KiB
PHP
Raw Normal View History

2022-03-15 21:38:39 +00:00
<?php
namespace Jump\Pages;
abstract class AbstractPage {
protected \Mustache_Engine $mustache;
private array $outputarray;
/**
* Construct an instance of a page.
*
* @param \Jump\Config $config
* @param \Jump\Cache $cache
* @param string|null $generic param, passed from router.
*/
public function __construct(protected \Jump\Config $config, protected \Jump\Cache $cache, protected ?string $param = null) {
$this->hastags = false;
$this->mustache = new \Mustache_Engine([
'loader' => new \Mustache_Loader_FilesystemLoader($this->config->get('templatedir'))
]);
}
abstract protected function render_content(): string;
protected function render_header(): string {
$template = $this->mustache->loadTemplate('header');
return $template->render([
'noindex' => $this->config->parse_bool($this->config->get('noindex')),
'title' => $this->config->get('sitename'),
'owmapikey' => !!$this->config->get('owmapikey', false),
'metrictemp' => $this->config->parse_bool($this->config->get('metrictemp'))
]);
}
protected function render_footer(): string {
$template = $this->mustache->loadTemplate('footer');
return $template->render([
'showclock' => $this->config->parse_bool($this->config->get('showclock'))
]);
}
protected function render_page(): void {
$this->outputarray = [
$this->render_header(),
$this->render_content(),
$this->render_footer(),
];
}
public function get_output(): string {
$this->render_page();
return implode('', $this->outputarray);
}
}