aboutsummaryrefslogtreecommitdiffhomepage
path: root/inc/3rdparty/PicoFarad/Template.php
diff options
context:
space:
mode:
authorNicolas LÅ“uillet <nicolas@loeuillet.org>2014-07-11 17:06:51 +0200
committerNicolas LÅ“uillet <nicolas@loeuillet.org>2014-07-11 17:06:51 +0200
commitb3cda72e93fff3a4c3476e9e7e78ef2b2a3f02b9 (patch)
treefb23b73225da5bc3a4466a51915586f60dde802c /inc/3rdparty/PicoFarad/Template.php
parent3602405ec0dbc576fce09ff9e865ba2404622080 (diff)
downloadwallabag-b3cda72e93fff3a4c3476e9e7e78ef2b2a3f02b9.tar.gz
wallabag-b3cda72e93fff3a4c3476e9e7e78ef2b2a3f02b9.tar.zst
wallabag-b3cda72e93fff3a4c3476e9e7e78ef2b2a3f02b9.zip
PicoFarad framework for routing
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}