diff options
| -rw-r--r-- | src/DTS/Template.php | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/src/DTS/Template.php b/src/DTS/Template.php new file mode 100644 index 0000000..89bd7f8 --- /dev/null +++ b/src/DTS/Template.php @@ -0,0 +1,32 @@ +<?php + +declare(strict_types=1); + +namespace DTS; + +class Template +{ + private string $path; + + function __construct(string $path) + { + $this->path = $path; + } + + public function render(string $template, array $data = []): string + { + $file = "{$this->path}$template.php"; + + if (!is_file($file) || !is_readable($file)) { + throw new \Exception("Unable to locate template $file"); + } + + extract($data); + + ob_start(); + + require_once($file); + + return ob_get_clean(); + } +} |
