diff options
author | Nicolas LÅ“uillet <nicolas@loeuillet.org> | 2014-07-11 17:06:51 +0200 |
---|---|---|
committer | Nicolas LÅ“uillet <nicolas@loeuillet.org> | 2014-07-11 17:06:51 +0200 |
commit | b3cda72e93fff3a4c3476e9e7e78ef2b2a3f02b9 (patch) | |
tree | fb23b73225da5bc3a4466a51915586f60dde802c /inc/3rdparty/PicoFarad/Template.php | |
parent | 3602405ec0dbc576fce09ff9e865ba2404622080 (diff) | |
download | wallabag-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.php | 36 |
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 | |||
3 | namespace PicoFarad\Template; | ||
4 | |||
5 | const PATH = 'templates/'; | ||
6 | |||
7 | // Template\load('template_name', ['bla' => 'value']); | ||
8 | function 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 | |||
33 | function 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 | } | ||