]> git.bts.cx Git - cx.git/blob - cx/lib/template.php
Custom markdown for inserting images
[cx.git] / cx / lib / template.php
1 <?php
2
3 function cx_template_render($class, $name, $variables = null) {
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 $base_template_variables = null;
15
16 $cx_template_base_previous = $cx_template_base;
17 $cx_template_base = function($name, $base_variables) use (&$base_template, &$base_template_variables) {
18 $base_template = $name;
19 $base_template_variables = $base_variables;
20 };
21
22 $cx_template_content_previous = $cx_template_content;
23 $cx_template_content = function() use ($output) {
24 return $output;
25 };
26
27 cx_require('lib', 'url.php'); // For templates
28
29 if ($variables != null) {
30 extract($variables);
31 }
32
33 ob_start();
34 include($path);
35 $output = ob_get_contents();
36 ob_end_clean();
37
38 $cx_template_base = $cx_template_base_previous;
39 $cx_template_content = $cx_template_content_previous;
40
41 $name = $base_template;
42 $variables = $base_template_variables;
43 }
44
45 return $output;
46 }
47
48 function cx_template_base($name, $variables = null) {
49 global $cx_template_base;
50 $cx_template_base($name, $variables);
51 }
52
53 function cx_template_content() {
54 global $cx_template_content;
55 return $cx_template_content();
56 }