diff --git a/src/novaconium.php b/src/novaconium.php index f60861d..4a12c7a 100644 --- a/src/novaconium.php +++ b/src/novaconium.php @@ -7,6 +7,9 @@ if (file_exists(\BASEPATH . '/App/config.php')) { require_once \FRAMEWORKPATH . '/skeleton/novaconium/App/config.php'; } +require_once \FRAMEWORKPATH . '/src/functions.php'; +require_once \FRAMEWORKPATH . '/src/twig.php'; + // --- Logging --- use Novaconium\Logger; $log = new Logger(\BASEPATH . $config['logfile'], $config['loglevel']); @@ -47,4 +50,4 @@ $redirect = new Redirect(); // --- Router --- use Novaconium\Router; $router = new Router(); -require_once \BASEPATH . $router->controllerPath; +require_once $router->controllerPath; diff --git a/src/twig.php b/src/twig.php index 8b354ce..1611aea 100644 --- a/src/twig.php +++ b/src/twig.php @@ -17,12 +17,10 @@ function view(string $name = '', array $moreData = []): bool { global $config, $data; - // Ensure $data is always an array if (!is_array($data)) { $data = []; } - // Merge additional data if (!empty($moreData)) { $data = array_merge($data, $moreData); } @@ -31,23 +29,29 @@ function view(string $name = '', array $moreData = []): bool // Setup Twig // ---------------------------------------- - $loader = new FilesystemLoader([ - BASEPATH . '/App/views/', - FRAMEWORKPATH . '/twig', - FRAMEWORKPATH . '/views', - BASEPATH . '/App/templates/override' - ]); + $loader = new FilesystemLoader(BASEPATH . '/App/views/'); + + // Add namespace paths + if (is_dir(FRAMEWORKPATH . '/twig')) { + $loader->addPath(FRAMEWORKPATH . '/twig', 'novaconium'); + } + + if (is_dir(FRAMEWORKPATH . '/views')) { + $loader->addPath(FRAMEWORKPATH . '/views', 'novacore'); + } + + if (is_dir(BASEPATH . '/App/templates')) { + $loader->addPath(BASEPATH . '/App/templates', 'override'); + } $twig = new Environment($loader); - // Add global config $twig->addGlobal('config', $config); // ---------------------------------------- // Render template // ---------------------------------------- - // Direct App override template $appTemplatePath = BASEPATH . '/App/views/' . $name . '.html.twig'; if (file_exists($appTemplatePath)) { @@ -55,13 +59,11 @@ function view(string $name = '', array $moreData = []): bool return true; } - // Namespaced Twig templates like @novaconium/whatever if (str_starts_with($name, '@')) { echo $twig->render($name . '.html.twig', $data); return true; } - // Fallback echo "Error: Twig Template ($name) Not Found."; return false; -} \ No newline at end of file +}