aboutsummaryrefslogtreecommitdiffhomepage
path: root/inc/3rdparty/PicoFarad/Template.php
diff options
context:
space:
mode:
Diffstat (limited to 'inc/3rdparty/PicoFarad/Template.php')
-rw-r--r--inc/3rdparty/PicoFarad/Template.php36
1 files changed, 36 insertions, 0 deletions
diff --git a/inc/3rdparty/PicoFarad/Template.php b/inc/3rdparty/PicoFarad/Template.php
new file mode 100644
index 00000000..c32be309
--- /dev/null
+++ b/inc/3rdparty/PicoFarad/Template.php
@@ -0,0 +1,36 @@
1<?php
2
3namespace PicoFarad\Template;
4
5const PATH = 'templates/';
6
7// Template\load('template_name', ['bla' => 'value']);
8function load()
9{
10 if (func_num_args() < 1 || func_num_args() > 2) {
11 die('Invalid template arguments');
12 }
13
14 if (! file_exists(PATH.func_get_arg(0).'.php')) {
15 die('Unable to load the template: "'.func_get_arg(0).'"');
16 }
17
18 if (func_num_args() === 2) {
19
20 if (! is_array(func_get_arg(1))) {
21 die('Template variables must be an array');
22 }
23
24 extract(func_get_arg(1));
25 }
26
27 ob_start();
28 include PATH.func_get_arg(0).'.php';
29 return ob_get_clean();
30}
31
32
33function layout($template_name, array $template_args = array(), $layout_name = 'layout')
34{
35 return load($layout_name, $template_args + array('content_for_layout' => load($template_name, $template_args)));
36}