diff --git a/src/Service/Template.php b/src/Service/Template.php index 2cce064..071662c 100644 --- a/src/Service/Template.php +++ b/src/Service/Template.php @@ -1,18 +1,36 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ namespace App\Service; -use Exception; - +/* + * As I'm not allowed to use 3rd party code like Twig or Smarty I ended up + * using PHP as a templating engine. + */ class Template { + /* + * Just store the information about the template base dir. + */ public function __construct(private readonly string $templateDir) { // empty body } - public function render(string $templateName): void + /* + * Add variables to template and throw it out + */ + public function render(string $templateName, array $vars = []): void { + foreach ($vars as $name => $value) { + $$name = $value; + } + include $this->templateDir . $templateName; } -} \ No newline at end of file +}