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 4
4
Application helpers
5
5
*/
6
6
7
- use Monster \App \Models \Env ;
8
-
9
7
// Load Thems
10
- function view ($ path , $ data = [])
8
+ function view ($ path , $ data = [], $ javascript = false )
11
9
{
12
- // Replace all . to /
10
+ // Replace all . with /
13
11
$ path = str_replace ('. ' , '/ ' , $ path );
14
12
15
13
extract ($ data );
16
14
17
15
// include views folder path
18
16
$ viewPath = 'views/ ' . $ path . '.php ' ;
19
17
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 ();
22
22
23
23
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 ) ;
25
25
}
26
26
27
- include_once $ viewPath ;
28
- }
27
+ echo $ viewContent ;
28
+ }
You can’t perform that action at this time.
0 commit comments