From d183c4c1e0bc77799ddeb9d144c2c496e01fc18f Mon Sep 17 00:00:00 2001 From: Nick Yeoman Date: Mon, 3 Mar 2025 12:23:02 -0800 Subject: [PATCH] Database allowed empty, twig grabs global vars --- README.md | 3 +++ docs/twig-overrides.md | 3 +++ src/novaconium.php | 6 ++++-- src/twig.php | 15 +++++++++++---- 4 files changed, 21 insertions(+), 6 deletions(-) create mode 100644 docs/twig-overrides.md diff --git a/README.md b/README.md index 83e00f8..0e494f0 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,10 @@ Master Repo: https://git.4lt.ca/4lt/novaconium ```bash mkdir project_name; cd project_name; +# Native composer require 4lt/novaconium +# Composer +docker run --rm --interactive --tty --volume $PWD:/app composer require 4lt/novaconium cp -R vendor/4lt/novaconium/defaults/App/ . cp -R vendor/4lt/novaconium/defaults/public/ . ``` diff --git a/docs/twig-overrides.md b/docs/twig-overrides.md new file mode 100644 index 0000000..2370074 --- /dev/null +++ b/docs/twig-overrides.md @@ -0,0 +1,3 @@ +# Twig Overrides + +You can override twig templates by creating the same file in the templates directory. diff --git a/src/novaconium.php b/src/novaconium.php index 0833e0d..7c5c6b9 100644 --- a/src/novaconium.php +++ b/src/novaconium.php @@ -18,8 +18,10 @@ require_once(FRAMEWORKPATH . '/src/Session.php'); $session = new Session(); // Load Database Class -require_once(FRAMEWORKPATH . '/src/Database.php'); -$db = new Database($config['database']); +if (!empty($config['database']['host'])) { + require_once(FRAMEWORKPATH . '/src/Database.php'); + $db = new Database($config['database']); +} // Load a controller require_once(FRAMEWORKPATH . '/src/Router.php'); diff --git a/src/twig.php b/src/twig.php index f0225b0..8f3b278 100644 --- a/src/twig.php +++ b/src/twig.php @@ -1,14 +1,21 @@ addPath(BASEPATH . '/vendor/4lt/novaconium/twig', 'novaconium'); $loader->addPath(BASEPATH . '/App/templates', 'override'); - $twig = new Twig\Environment($loader); - //check if file exists + + $twig = new Twig\Environment($loader); + + // Add config to Twig globally + $twig->addGlobal('config', $config); + + // Check if the template exists if (file_exists(BASEPATH . '/App/views/' . $name . '.html.twig')) { - echo $twig->render("$name" . '.html.twig', $data); + echo $twig->render("$name.html.twig", $data); return true; } else { echo "Error: Twig Template ($name) Not Found.";