novaconium/controllers/samples.php

35 lines
899 B
PHP

<?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');
}