<?php

function view(string $path, array $data = []): string
{
  $file = __DIR__ . '/../templates/' . $path;
  if(!file_exists($file)) {
     throw new Exception('Tempalate not found');
  }

  $content = file_get_contents($file);

  // Templating Engine 
  foreach($data as $key => $value) {
    $content = str_replace(
      '['.$key.']', 
      htmlspecialchars((string) $value, ENT_QUOTES, 'UTF-8'),
      $content,
    );
  }

  return $content;
}