tkr/src/Controller/Controller.php
Greg Sarjeant 3df38de9fb Change ConfigModel to SettingsModel (#62)
Reviewed-on: https://gitea.subcultureofone.org/greg/tkr/pulls/62
Co-authored-by: Greg Sarjeant <greg@subcultureofone.org>
Co-committed-by: Greg Sarjeant <greg@subcultureofone.org>
2025-08-08 19:44:31 +00:00

40 lines
1.4 KiB
PHP

<?php
declare(strict_types=1);
class Controller {
// Renders the requested template inside templates/main/php
protected function render(string $childTemplateFile, array $vars = []) {
$templatePath = TEMPLATES_DIR . "/main.php";
$childTemplatePath = TEMPLATES_DIR . "/partials/" . $childTemplateFile;
if (!file_exists($templatePath)) {
throw new RuntimeException("Template not found: $templatePath");
}
if (!file_exists($childTemplatePath)) {
throw new RuntimeException("Template not found: $childTemplatePath");
}
// Add custom CSS filename if needed
global $app;
if ($app['settings']->cssId) {
$cssModel = new CssModel($app['db']);
$cssFile = $cssModel->getById($app['settings']->cssId);
$vars['customCssFilename'] = $cssFile['filename'] ?? null;
} else {
$vars['customCssFilename'] = null;
}
// always check for flash messages and add them if they exist
if (Session::hasFlashMessages()){
$flashMessages = Session::getFlashMessages();
$flashView = new FlashView();
$flashSection = $flashView->renderFlashSection($flashMessages);
$vars['flashSection'] = $flashSection;
}
extract($vars, EXTR_SKIP);
include $templatePath;
}
}