ref: master
app/helpers/Template.php
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
<?php class Template { public static function render($view, $data = []) { // TODO: Add support for multiple controller/pages? $viewPath = __DIR__ . '/../views/' . $view . '.php'; $layoutPath = __DIR__ . '/../views/layout.php'; if (!file_exists($viewPath)) { throw new Exception("View not found: " . $view); } extract($data); ob_start(); include $viewPath; $content = ob_get_clean(); // Render within layout ob_start(); include $layoutPath; return ob_get_clean(); return $content; } } |