die with error message if template doesn't exist.
This commit is contained in:
parent
b60d9481ab
commit
33618b3be0
@ -12,6 +12,9 @@ namespace App\Service;
|
||||
* As I'm not allowed to use 3rd party code like Twig or Smarty I ended up
|
||||
* using PHP as a templating engine.
|
||||
*/
|
||||
|
||||
use JetBrains\PhpStorm\NoReturn;
|
||||
|
||||
class Template
|
||||
{
|
||||
/*
|
||||
@ -25,13 +28,20 @@ class Template
|
||||
/*
|
||||
* Add variables to template and throw it out
|
||||
*/
|
||||
#[NoReturn]
|
||||
public function render(string $templateName, array $vars = []): void
|
||||
{
|
||||
// assign template vars
|
||||
foreach ($vars as $name => $value) {
|
||||
$$name = $value;
|
||||
}
|
||||
|
||||
include $this->templateDir . $templateName;
|
||||
$templateFile = $this->templateDir . $templateName;
|
||||
if (file_exists(filename: $templateFile)) {
|
||||
include $this->templateDir . $templateName;
|
||||
} else {
|
||||
die("Missing template: $templateFile");
|
||||
}
|
||||
exit(0);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user