JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
added: tem_merge(), tem_merge_file()
[wfpl.git] / template.php
index 85132c3..af66590 100644 (file)
@@ -64,8 +64,7 @@ function parse_template_file($filename) {
 function parse_template($string) {
        $tem =& tem_push();
        $tem['pieces'] = array();
-       # note: for some reason this captures '<!--' but not '-->'.
-       $matches = preg_split("/(<!--)?(~[^~]*~)(?(1)-->)/", $string, -1, PREG_SPLIT_DELIM_CAPTURE);
+       $matches = preg_split('/(<!--)?(~[^~]*~)(?(1)-->)/', preg_replace('/<!--(~[^~]*~)-->/', '$1', $string), -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
        foreach($matches as $match) {
                if($match == '~~') $match = '~';
                if(substr($match,0,1) == '~' and strlen($match) > 2) {
@@ -91,7 +90,7 @@ function parse_template($string) {
                        } else {  # value slot
                                $tem['pieces'][] = array('name' => $name, 'args' => $args);
                        }
-               } elseif($match and $match != '<!--') {  # static string
+               } else {  # static string
                        $tem['pieces'][] = $match;
                }
        }
@@ -446,6 +445,13 @@ class tem {
                $this->template = merge_templates($this->template, $tem->template);
        }
 
+       # see merge() above
+       function merge_file($filename) {
+               $other_tem = new tem();
+               $other_tem->load($filename);
+               $this->merge($other_tem);
+       }
+
        function top_sub_names($is_sub = 'is_sub_template') {
                return array_keys(top_sub_templates($this->template, $is_sub));
        }
@@ -511,6 +517,16 @@ function tem_load($filename) {
        $GLOBALS['wfpl_template']->load($filename);
 }
 
+function tem_merge($tem) {
+       tem_init();
+       $GLOBALS['wfpl_template']->merge($tem);
+}
+
+function tem_merge_file($filename) {
+       tem_init();
+       $GLOBALS['wfpl_template']->merge_file($filename);
+}
+
 function tem_output($filename = false) {
        tem_init();
        $GLOBALS['wfpl_template']->output($filename);