From bccad1118364427ea5c97c08d132fd128368760b Mon Sep 17 00:00:00 2001 From: winter Date: Mon, 23 Dec 2024 18:20:25 +0000 Subject: make a crummy template system and use it for global timeline --- misc/render_template.php | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 misc/render_template.php (limited to 'misc/render_template.php') diff --git a/misc/render_template.php b/misc/render_template.php new file mode 100644 index 0000000..1ee349d --- /dev/null +++ b/misc/render_template.php @@ -0,0 +1,48 @@ + $value) { + ${$key} = $value; + } + + if (!function_exists('slot')) { + function slot() { + global $__spooky_magical_template_global_state; + if (isset($__spooky_magical_template_global_state['slotParentArgs'])) { + $parentArgs = $__spooky_magical_template_global_state['slotParentArgs']; + foreach ($parentArgs as $key => $value) { + global ${$key}; + ${$key} = $value; + } + } + ($__spooky_magical_template_global_state['slotContent'] ?? function () {})(); + if (isset($parentArgs)) { + foreach ($parentArgs as $key => $value) { + unset(${$key}); + } + } + } + function call_template(string $templateName, array $args = [], callable $slotContent = null) { + global $__spooky_magical_template_global_state; + $__spooky_magical_template_global_state['slotContent'] = $slotContent; + render_template($templateName, $args); + } + } + + require __DIR__ . '/../templates/' . $templateName . '.php'; + + foreach ($args as $key => $value) { + unset(${$key}); + } +} \ No newline at end of file -- cgit v1.3