]> git.bts.cx Git - cx.git/blob - cx/lib/template.php
e368a2ead46a74436e8e28e3daa50ce052369797
[cx.git] / cx / lib / template.php
1 <?php
2
3 function cx_template_render($class, $name, $variables = []) {
4 global $cx_template_base, $cx_template_content;
5
6 $base_template = null;
7
8 $output = '';
9 while ($name != null) {
10 $segments = array(CX_PATH, 'templates', $class, $name . '.php');
11 $path = join(DIRECTORY_SEPARATOR, $segments);
12
13 $base_template = null;
14
15 $cx_template_base_previous = $cx_template_base;
16 $cx_template_base = function($name) use (&$base_template ) {
17 $base_template = $name;
18 };
19
20 $cx_template_content_previous = $cx_template_content;
21 $cx_template_content = function() use ($output) {
22 return $output;
23 };
24
25 cx_require('lib', 'url.php'); // For templates
26
27 extract($variables);
28 ob_start();
29 include($path);
30 $output = ob_get_contents();
31 ob_end_clean();
32
33 $cx_template_base = $cx_template_base_previous;
34 $cx_template_content = $cx_template_content_previous;
35
36 $name = $base_template;
37 }
38
39 return $output;
40 }
41
42 function cx_template_base($name) {
43 global $cx_template_base;
44 $cx_template_base($name);
45 }
46
47 function cx_template_content() {
48 global $cx_template_content;
49 return $cx_template_content();
50 }