diff options
| author | David T. Sadler <davidtsadler@googlemail.com> | 2021-11-13 09:22:25 +0000 |
|---|---|---|
| committer | David T. Sadler <davidtsadler@googlemail.com> | 2021-11-13 09:22:25 +0000 |
| commit | 40997195b7ee07cb1bda978186c1804371e1f16e (patch) | |
| tree | 17a6e4bd6eaca795cfa8d57b9aa6ea8ad7066593 /src/DTS/Template.php | |
| parent | 35dc6c245d93560d7ac81df6323e8b22e571aa95 (diff) | |
Create site
Diffstat (limited to 'src/DTS/Template.php')
| -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(); + } +} |
