From 7749b8ed569f6d27b0bb2ed4c2040e8b61ed4422 Mon Sep 17 00:00:00 2001 From: Frédéric Guillot Date: Sun, 9 Mar 2014 23:21:23 -0400 Subject: Automatic actions --- core/template.php | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 core/template.php (limited to 'core/template.php') diff --git a/core/template.php b/core/template.php new file mode 100644 index 00000000..ad31ffb7 --- /dev/null +++ b/core/template.php @@ -0,0 +1,40 @@ + 'value']); + public function load() + { + if (func_num_args() < 1 || func_num_args() > 2) { + die('Invalid template arguments'); + } + + if (! file_exists(self::PATH.func_get_arg(0).'.php')) { + die('Unable to load the template: "'.func_get_arg(0).'"'); + } + + if (func_num_args() === 2) { + + if (! is_array(func_get_arg(1))) { + die('Template variables must be an array'); + } + + extract(func_get_arg(1)); + } + + ob_start(); + + include self::PATH.func_get_arg(0).'.php'; + + return ob_get_clean(); + } + + public function layout($template_name, array $template_args = array(), $layout_name = 'layout') + { + return $this->load($layout_name, $template_args + array('content_for_layout' => $this->load($template_name, $template_args))); + } +} -- cgit v1.2.3