Skip to content

Commit ec93b59

Browse files
committed
chore: enhance layout core
1 parent 6988641 commit ec93b59

1 file changed

Lines changed: 63 additions & 30 deletions

File tree

app/core/Layout.php

Lines changed: 63 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,63 @@
1-
<?php
2-
3-
namespace app\core;
4-
5-
class Layout
6-
{
7-
protected $content;
8-
9-
public function __construct($content)
10-
{
11-
$this->content = $content;
12-
}
13-
14-
public function render($layoutPath = null, $cssPath = '')
15-
{
16-
17-
// Read warvil.json
18-
$jsonFile = file_get_contents('warvil.json');
19-
$warvilConfig = json_decode($jsonFile, true);
20-
21-
$baseStyle = Config::get('paths/styles/base');
22-
23-
if (file_exists($layoutPath)) {
24-
include_once $layoutPath;
25-
} else {
26-
// Handle the case when the layout file is not found
27-
echo 'Error: Layout file not found';
28-
}
29-
}
30-
}
1+
<?php
2+
3+
namespace app\core;
4+
5+
class Layout
6+
{
7+
protected $content;
8+
9+
public function __construct($content)
10+
{
11+
$this->content = $content;
12+
}
13+
14+
public function render($layoutPath = null, $cssPath = '')
15+
{
16+
// Read warvil.json
17+
$jsonFile = file_exists('warvil.json') ? file_get_contents('warvil.json') : '{}';
18+
$warvilConfig = json_decode($jsonFile, true) ?: [];
19+
20+
$baseStyle = Config::get('paths/styles/base');
21+
22+
// Process the layout path correctly
23+
if ($layoutPath === null) {
24+
// Use default layout from config
25+
$layoutPath = Config::get('paths/layouts/default');
26+
27+
// If still null, use a fallback path
28+
if ($layoutPath === null) {
29+
$layoutPath = 'app/shared/layouts/main.php';
30+
}
31+
} else if ($layoutPath === 'welcome') {
32+
// Handle 'welcome' layout string
33+
$layoutPath = 'app/shared/layouts/welcome.php';
34+
} else if (!str_contains($layoutPath, '/') && !str_contains($layoutPath, '\\')) {
35+
// If it's just a name without path separators, assume it's in the layouts directory
36+
$layoutPath = 'app/shared/layouts/' . $layoutPath . '.php';
37+
}
38+
39+
// Debug information
40+
if (defined('DEBUG') && DEBUG) {
41+
echo "<!-- Using layout: {$layoutPath} -->\n";
42+
}
43+
44+
if (file_exists($layoutPath)) {
45+
include_once $layoutPath;
46+
} else {
47+
// More helpful error message
48+
echo 'Error: Layout file not found: ' . $layoutPath;
49+
echo '<br>Please make sure the layout file exists or update the layout path in your configuration.';
50+
echo '<br>Available layouts: ';
51+
52+
// List available layouts
53+
if (is_dir('app/shared/layouts')) {
54+
$layouts = glob('app/shared/layouts/*.php');
55+
echo implode(', ', array_map(function($path) {
56+
return basename($path, '.php');
57+
}, $layouts));
58+
} else {
59+
echo 'No layouts directory found.';
60+
}
61+
}
62+
}
63+
}

0 commit comments

Comments
 (0)