Skip to content

Commit 741c105

Browse files
authored
fix
1 parent a774104 commit 741c105

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

routes/helpers/base.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,25 @@
44
Application helpers
55
*/
66

7-
use Monster\App\Models\Env;
8-
97
// Load Thems
10-
function view($path, $data = [])
8+
function view($path, $data = [], $javascript = false)
119
{
12-
// Replace all . to /
10+
// Replace all . with /
1311
$path = str_replace('.', '/', $path);
1412

1513
extract($data);
1614

1715
// include views folder path
1816
$viewPath = 'views/' . $path . '.php';
1917

20-
$env = new Env('.env');
21-
$javascript = $env->get("JAVASCRIPT_DATA");
18+
// Wrap the view rendering code in a buffer
19+
ob_start();
20+
include_once $viewPath;
21+
$viewContent = ob_get_clean();
2222

2323
if ($javascript == "true") {
24-
echo "<script>let monster = JSON.parse('" . json_encode($data) . "')</script>";
24+
$viewContent = str_replace('<title>', "<script>let monster = JSON.parse('" . json_encode($data) . "');</script>\n<title>", $viewContent);
2525
}
2626

27-
include_once $viewPath;
28-
}
27+
echo $viewContent;
28+
}

0 commit comments

Comments
 (0)