Database allowed empty, twig grabs global vars
This commit is contained in:
15
src/twig.php
15
src/twig.php
@@ -1,14 +1,21 @@
|
||||
<?php
|
||||
|
||||
//Twig
|
||||
function view($name = '', $data = [] ) {
|
||||
function view($name = '', $data = []) {
|
||||
global $config; // Use the globally included $config
|
||||
|
||||
$loader = new Twig\Loader\FilesystemLoader(BASEPATH . '/App/views/');
|
||||
$loader->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.";
|
||||
|
||||
Reference in New Issue
Block a user