Repository navigation
Expand file tree
/
Copy pathenvironment.php
More file actions
77 lines (65 loc) · 2.45 KB
/
Copy pathenvironment.php
File metadata and controls
77 lines (65 loc) · 2.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<?php
define( 'ABSPATH', __DIR__ . '/' );
define( 'APPDATA', __DIR__ . '/appdata/' );
define( 'LOGPATH', __DIR__ . '/logs/' );
require_once __DIR__ . '/vendor/autoload.php';
require_once __DIR__ . '/credentials.php';
// Session configuration
ini_set('session.cookie_httponly', 1);
ini_set('session.use_only_cookies', 1);
ini_set('session.cookie_secure', 0);
// Error reporting
error_reporting(E_ALL);
ini_set('display_errors', 1);
// Timezone
date_default_timezone_set('UTC');
if(!function_exists('sqlError__alertAndStop')){ function sqlError__alertAndStop($sql_error, $sql_query, $reference = '', $UserID = 0, $trace = null){
return time();
} }
/* Render a TWIG template
$twig_template = '/components/card.html';
$loader = new \Twig\Loader\FilesystemLoader(ABSPATH . 'templates/twig');
$twig = new \Twig\Environment($loader, [ 'debug' => true, 'cache' => ABSPATH . 'templates/cache/twig_compilation_cache', 'auto_reload' => true, 'strict_variables' => false, 'optimizations' => 1 ]);
echo $twig->render($twig_template . '.twig', [
'title' => 'Hello world',
'content' => '<p>Lorem ispum</p>'
]);
*/
// Global Twig setup
$GLOBALS['twig_loader'] = new \Twig\Loader\FilesystemLoader(ABSPATH . 'templates/twig');
$GLOBALS['twig_env'] = new \Twig\Environment($GLOBALS['twig_loader'], [
'debug' => true,
'cache' => ABSPATH . 'templates/cache/twig_compilation_cache',
'auto_reload' => true,
'strict_variables' => false,
'optimizations' => 1
]);
/**
* Render Twig template with elegant syntax
*
* @param string $template - Template path with @ prefix (@components/card.twig or @some-file.twig)
* @param array $data - Data to pass to template
* @return string - Rendered HTML
*
* @ai-meta Look for .meta.json files in template directories for component usage
* @ai-guide /docs-ai/how-to-render-twig-templates.md Usage patterns and syntax
*/
function twig($template, $data = []) {
// Remove @ prefix
$template = ltrim($template, '@');
// If no directory specified, look in root
if (strpos($template, '/') === false) {
$template_path = $template;
} else {
$template_path = $template;
}
// Ensure .twig extension
if (!str_ends_with($template_path, '.twig')) {
$template_path .= '.twig';
}
try {
return $GLOBALS['twig_env']->render($template_path, $data);
} catch (\Twig\Error\LoaderError $e) {
throw new Exception("Twig template not found: {$template_path}");
}
}