Removed custom template logic, just use PHP as a template engine.
This commit is contained in:
parent
87959d34b7
commit
a55b14c71c
|
@ -11,30 +11,8 @@ class Template
|
||||||
// empty body
|
// empty body
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @throws Exception
|
|
||||||
*/
|
|
||||||
public function render(string $templateName): void
|
public function render(string $templateName): void
|
||||||
{
|
{
|
||||||
$template = file_get_contents(filename: $this->templateDir . $templateName);
|
include $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;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue