diff --git a/core/View/View.php b/core/View/View.php index 685cab2..ebbdf2e 100644 --- a/core/View/View.php +++ b/core/View/View.php @@ -15,9 +15,9 @@ public static function init() { $viewsPath = __DIR__ . '/../../app/Views'; $loader = new FilesystemLoader($viewsPath); - + $twigConfig = config('view.twig', []); - + // Configure cache properly $cacheEnv = $twigConfig['cache'] ?? false; $cachePath = false; // Default to no cache @@ -27,7 +27,7 @@ public static function init() mkdir($cachePath, 0777, true); } } - + self::$twig = new Environment($loader, [ 'cache' => $cachePath, 'debug' => $twigConfig['debug'] ?? true, @@ -43,11 +43,12 @@ public static function init() // Register helpers for Twig: auto-register all from helpers.php, merge with config('view.twig_helpers') if set. self::registerExplicitHelpers(); } - + /** * Register helpers for Twig: auto-register all from helpers.php, merge with config('view.twig_helpers') if set. */ - private static function registerExplicitHelpers() { + private static function registerExplicitHelpers() + { // 1. Get all user-defined functions (auto-discover from helpers.php and any loaded helpers) $userFunctions = get_defined_functions()['user']; @@ -60,7 +61,9 @@ private static function registerExplicitHelpers() { // 4. Register each helper if it exists foreach ($allHelpers as $helper) { if (function_exists($helper)) { - self::$twig->addFunction(new \Twig\TwigFunction($helper, $helper)); + self::$twig->addFunction(new TwigFunction($helper, $helper)); + } else { + log_error("[SproutPHP] Warning: Twig helper function '$helper' does not exist and was not registered."); } } } @@ -75,13 +78,13 @@ public static function render($template, $data = [], $return = false) if (Debugbar::isAjaxRequest() && config('app.debug', false)) { // Reset debugbar for this request Debugbar::resetForRequest(); - + // Render the template first $content = self::$twig->render($template . '.twig', $data); - + // Append debugbar to the response $debugbar = Debugbar::render(); - + if ($return) { return $content . $debugbar; }