Skip to content

Commit a46ee78

Browse files
authored
add tcss
1 parent 291eed2 commit a46ee78

File tree

1 file changed

+24
-5
lines changed

1 file changed

+24
-5
lines changed

routes/helpers/base.php

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,46 @@
11
<?php
2+
use Monster\App\Models\Env;
23

34
/*
45
Application helpers
56
*/
67

7-
// Load Thems
8-
function view($path, $data = [], $javascript = false)
8+
// Load Views
9+
function view($path, $data = [], $javascript = false, $tcss = false)
910
{
11+
$env = new Env('.env');
12+
$tcss_path = $env->get("TCSS_MIN");
13+
1014
// Replace all . with /
1115
$path = str_replace('.', '/', $path);
1216

1317
extract($data);
1418

15-
// include views folder path
19+
// Include views folder path
1620
$viewPath = 'views/' . $path . '.php';
1721

22+
// Check if the view file exists
23+
if (!file_exists($viewPath)) {
24+
// Handle the error, e.g., throw an exception or show a 404 error
25+
exit('View does not exist.');
26+
}
27+
1828
// Wrap the view rendering code in a buffer
1929
ob_start();
2030
include_once $viewPath;
2131
$viewContent = ob_get_clean();
2232

23-
if ($javascript == "true") {
24-
$viewContent = str_replace('<title>', "<script>let monster = JSON.parse('" . json_encode($data) . "');</script>\n<title>", $viewContent);
33+
// Inject JavaScript if $javascript is true
34+
if ($javascript) {
35+
$encodedData = json_encode($data);
36+
$viewContent = str_replace('<title>', "<script>let monster = JSON.parse('{$encodedData}');</script>\n<title>", $viewContent);
37+
}
38+
39+
// Inject CSS if $tcss is true
40+
if ($tcss) {
41+
// Assuming you have a specific CSS file to include
42+
$cssLink = '<link rel="stylesheet" href="' . $tcss_path . '">';
43+
$viewContent = str_replace('<title>', "{$cssLink}\n<title>", $viewContent);
2544
}
2645

2746
echo $viewContent;

0 commit comments

Comments
 (0)