Removed custom template logic, just use PHP as a template engine.

This commit is contained in:
tracer 2022-10-22 13:11:52 +02:00
parent 87959d34b7
commit a55b14c71c

View File

@ -11,30 +11,8 @@ class Template
// empty body
}
/**
* @throws Exception
*/
public function render(string $templateName): void
{
$template = file_get_contents(filename: $this->templateDir . $templateName);
// search for includes
preg_match_all(pattern: '/{% include ?\'?(.*?)\'? ?%}/i', subject: $template, matches: $matches, flags: PREG_SET_ORDER);
foreach ($matches as $value) {
$token = $value[0];
$include = $this->templateDir . $value[1];
if (file_exists(filename: $include)) {
$replacement = file_get_contents(filename: $include);
} else {
throw new Exception(message: "Missing included file: $include");
}
$template = str_replace(search: $token, replace: $replacement, subject: $template);
}
// remove the original template code
$template = preg_replace(pattern: '/{% include ?\'?(.*?)\'? ?%}/i', replacement: '', subject: $template);
echo $template;
include $this->templateDir . $templateName;
}
}