Skip to content

Commit

Permalink
add tcss
Browse files Browse the repository at this point in the history
  • Loading branch information
ReactMVC authored Jan 10, 2024
1 parent 291eed2 commit a46ee78
Showing 1 changed file with 24 additions and 5 deletions.
29 changes: 24 additions & 5 deletions routes/helpers/base.php
Original file line number Diff line number Diff line change
@@ -1,27 +1,46 @@
<?php
use Monster\App\Models\Env;

/*
Application helpers
*/

// Load Thems
function view($path, $data = [], $javascript = false)
// Load Views
function view($path, $data = [], $javascript = false, $tcss = false)
{
$env = new Env('.env');
$tcss_path = $env->get("TCSS_MIN");

// Replace all . with /
$path = str_replace('.', '/', $path);

extract($data);

// include views folder path
// Include views folder path
$viewPath = 'views/' . $path . '.php';

// Check if the view file exists
if (!file_exists($viewPath)) {
// Handle the error, e.g., throw an exception or show a 404 error
exit('View does not exist.');
}

// Wrap the view rendering code in a buffer
ob_start();
include_once $viewPath;
$viewContent = ob_get_clean();

if ($javascript == "true") {
$viewContent = str_replace('<title>', "<script>let monster = JSON.parse('" . json_encode($data) . "');</script>\n<title>", $viewContent);
// Inject JavaScript if $javascript is true
if ($javascript) {
$encodedData = json_encode($data);
$viewContent = str_replace('<title>', "<script>let monster = JSON.parse('{$encodedData}');</script>\n<title>", $viewContent);
}

// Inject CSS if $tcss is true
if ($tcss) {
// Assuming you have a specific CSS file to include
$cssLink = '<link rel="stylesheet" href="' . $tcss_path . '">';
$viewContent = str_replace('<title>', "{$cssLink}\n<title>", $viewContent);
}

echo $viewContent;
Expand Down

0 comments on commit a46ee78

Please sign in to comment.