404 fixes and added pure twig
This commit is contained in:
4
controllers/404.php
Normal file
4
controllers/404.php
Normal file
@@ -0,0 +1,4 @@
|
||||
<?php
|
||||
http_response_code('404');
|
||||
header("Content-Type: text/html");
|
||||
view('@novacore/404');
|
||||
34
controllers/samples.php
Normal file
34
controllers/samples.php
Normal file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
/**
|
||||
* Pure Twig, no db example
|
||||
*
|
||||
* Replicate Hugo but with html and twig (not markdown)
|
||||
**/
|
||||
|
||||
// Variables
|
||||
$pt = '@novacore/samples'; //Define the view directory
|
||||
//$pt = 'samples'; //drop the core for your project
|
||||
|
||||
//Grab the slug
|
||||
$slug = $router->parameters['slug'];
|
||||
|
||||
//build path
|
||||
$tmpl = $pt . '/' . $slug;
|
||||
|
||||
//Check if file exits
|
||||
$baseDir = (strpos($pt, 'novacore') !== false) ? FRAMEWORKPATH : BASEPATH;
|
||||
if (strpos($pt, '@novacore') !== false) {
|
||||
$baseDir = str_replace('@novacore', FRAMEWORKPATH . '/views', $pt);
|
||||
} else {
|
||||
$baseDir = str_replace('@novacore', BASEPATH . '/views', $pt);
|
||||
}
|
||||
|
||||
$possibleFile = $baseDir . '/' . $slug . '.html.twig'; // add .twig extension if needed
|
||||
|
||||
if (is_file($possibleFile) && is_readable($possibleFile)) {
|
||||
view($tmpl, $data);
|
||||
} else {
|
||||
http_response_code('404');
|
||||
header("Content-Type: text/html");
|
||||
view('@novacore/404');
|
||||
}
|
||||
Reference in New Issue
Block a user