File tree Expand file tree Collapse file tree 1 file changed +9
-9
lines changed Expand file tree Collapse file tree 1 file changed +9
-9
lines changed Original file line number Diff line number Diff line change 44Application 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+ }
You can’t perform that action at this time.
0 commit comments