From 80f41c53279b780b278c7478d67f834d889a8b0c Mon Sep 17 00:00:00 2001 From: Benjamin Renard Date: Thu, 2 Mar 2023 15:02:59 +0100 Subject: [PATCH] Tpl: add register_class method and make App class available in templates --- src/Tpl.php | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/Tpl.php b/src/Tpl.php index 2dd817f..7e86bd7 100644 --- a/src/Tpl.php +++ b/src/Tpl.php @@ -177,9 +177,9 @@ class Tpl { foreach(App :: get('templates.static_directories', null, 'array') as $path) self :: register_static_directory($path); - - self :: register_function('var_dump', array('EesyPHP\\Tpl', 'smarty_var_dump')); } + self :: register_function('var_dump', array('EesyPHP\\Tpl', 'smarty_var_dump')); + self :: register_class('App', '\\EesyPHP\\App'); } /** @@ -223,6 +223,16 @@ class Tpl { self :: $smarty -> registerPlugin("function", $name, $callable); } + /** + * Register a class usable from template files + * @param string $class_name The class name + * @param string $class_ref The class reference (eg: \EesyPHP\App) + * @return void + */ + public static function register_class($class_name, $class_ref) { + self :: $smarty -> registerClass($class_name, $class_ref); + } + /** * Assign template variable * @param string $name The variable name