From 754ff1fda76b89da6793b5e553bd127cb4076571 Mon Sep 17 00:00:00 2001 From: Jonas Kohl Date: Tue, 10 Dec 2024 15:57:41 +0100 Subject: Add ability to add context functions --- src/index.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/index.php b/src/index.php index 4c53f0c..b7e0397 100644 --- a/src/index.php +++ b/src/index.php @@ -149,7 +149,7 @@ function reArrayFiles(&$file_post) { return $file_ary; } -function render(string $page, array $context = []): void { +function render(string $page, array $context = [], array $functions = []): void { $defaultTemplate = "bootstrap-3"; // bootstrap-3 is the default for backwards compatibility $templateDir = __ROOT__ . "/application/templates"; @@ -193,6 +193,9 @@ function render(string $page, array $context = []): void { $twig->addFilter(new TwigFilter("base64_encode", base64_encode(...))); $twig->addFilter(new TwigFilter("base64_decode", base64_decode(...))); + foreach ($functions as $fnName => $callable) + $twig->addFunction(new TwigFunction("ctx_$fnName", $callable)); + echo $twig->render($page, [ "g" => [ "get" => &$_GET, -- cgit v1.2.3