Dynadot — .com Registration $8.99

What Php template engine do you use?

Spaceship Spaceship
Watch

axilant

Account Closed
Impact
28
Currently, i use my own template engine.... but theres a few bugs in it. I was wondering what all the other advanced php users here use as there template engine. Please provide a link :)

I would use smarty, but imo there's too much overhead. The only way i would use smarty is there was a watered down version...
 
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
GoDaddyGoDaddy
0
•••
I like btemplate, but the problem is it wont parse a if-statement more than once. If that bug would be fix, along with the loop (loop works, but you have to rebuild a few functions and its a great template engine imo...)

Ill see what i can do about getting it fixed. :P And once i get it fixed, ill add-on to it...

Thanks for the nice read ;)
 
0
•••
it's very easy to work around that 'limitation' and all in all it's a great templating system. Compare it with smarty and you'll be glad you went with it...believe me :D

Lux
 
0
•••
luxinterior said:
it's very easy to work around that 'limitation' and all in all it's a great templating system. Compare it with smarty and you'll be glad you went with it...believe me :D

Lux

Do you use btemplate? I have used it before, problem is there is a bug in it... i have one fixed, now it doesnt parse the loops O.o

PHP:
<?php

    class Btemplate
    {
        var $base_path;
        var $reset_vars;
        var $ldelim = '<';
        var $rdelim = ' />';
        var $BAldelim = '<';
        var $BArdelim = '>';
        var $EAldelim = '</';
        var $EArdelim = '>';
        var $scalars = array();
        var $arrays  = array();
        var $carrays = array();
        var $ifs = array();

        function Btemplate($base_path = NULL, $reset_vars = TRUE) {
            if ($base_path) {
                $this->base_path = $base_path;
            }
            $this->reset_vars = $reset_vars;
        }

        function set($tag, $var, $if = NULL) {
            if (is_array($var)) {
                $this->arrays[$tag] = $var;
                if ($if) {
                    $result = $var ? TRUE : FALSE;
                    $this->ifs[] = $tag;
                    $this->scalars[$tag] = $result;
                }
            } else {
                $this->scalars[$tag] = $var;
                if ($if) {
                    $this->ifs[] = $tag;
                }
            }
        }

        function set_cloop($tag, $array, $cases) {
            $this->carrays[$tag] = array(
                'array' => $array,
                'cases' => $cases);
        }
    
        function reset_vars($scalars, $arrays, $carrays, $ifs) {
            if ($scalars==true) { $this->scalars = array(); }
            if ($arrays==true)  { $this->arrays  = array(); }
            if ($carrays==true) { $this->carrays = array(); }
            if ($ifs==true) { $this->ifs = array(); }
        }
    
        function get_tags($tag, $directive) {
            $tags['b'] = $this->BAldelim . $directive . $tag . $this->BArdelim;
            $tags['e'] = $this->EAldelim . $directive . $tag . $this->EArdelim;
            return $tags;
        }
    
        function get_tag($tag) {
            return $this->ldelim . 'tag:' . $tag . $this->rdelim;
        }
    
        function get_statement($t, &$contents) {
            $tag_length = strlen($t['b']);
            $tags = array();
            
            $fpos = strpos($contents, $t['b']) + $tag_length;
            
            while ($fpos) {
                $lpos = strpos($contents, $t['e'], $fpos);
                $length = $lpos - $fpos;
                $tags[] = substr($contents, $fpos, $length);
                $fpos = strpos($contents, $t['b'], $lpos);
            }
            return $tags;
        }
    
        function parse(&$contents) {
            if (!empty($this->ifs)) {
                foreach($this->ifs as $value) {
                    $contents = $this->parse_if($value, $contents);
                }
            }
    
            foreach($this->scalars as $key => $value) {
                $contents = str_replace($this->get_tag($key), $value, $contents);
            }
    
            foreach($this->arrays as $key => $array) {
                $contents = $this->parse_loop($key, $array, $contents);
            }
    
            foreach($this->carrays as $key => $array) {
                $contents = $this->parse_cloop($key, $array, $contents);
            }
    
            if ($this->reset_vars) {
                $this->reset_vars(FALSE, TRUE, TRUE, TRUE);
            }
            return $contents;
        }
    
        function parse_if($tag, &$contents) {
            $t = $this->get_tags($tag, 'if:');
            $entire_statement = $this->get_statement($t, $contents);
            $num_statements = count($entire_statement);
            
            for($x = 0; $x < $num_statements; $x++) {
                $else_tags = array(
                        'b' => NULL,
                        'e' => $this->BAldelim . 'else:' . $tag . $this->BArdelim
                    );

                $else_pos = strpos($entire_statement[$x], $else_tags['e']);
                
                if ($else_pos) {
                    $if = substr($entire_statement[$x], 0, $else_pos);
                    $else = substr($entire_statement[$x], $else_pos + strlen($else_tags['e']));
                } else {
                    $else = NULL;
                    $if = $entire_statement[$x];
                }

                $this->scalars[$tag] ? $replace = $if : $replace = $else;
                $contents = str_replace($entire_statement[$x], $replace, $contents);
            }
            return $contents;
        }
    
        function parse_loop($tag, $array, $contents) {
            $t = $this->get_tags($tag, 'loop:');
            $loop = $this->get_statement($t, $contents);
            $parsed = NULL;
    
            foreach($array as $key => $value) {
                if (is_numeric($key) && is_array($value)) {
                    $i = $loop;
                    foreach($value as $key2 => $value2) {
                        if (!is_array($value2)) {
                            $i = str_replace($this->get_tag($tag . '[].' . $key2), $value2, $i);
                        } else {
                            $i = $this->parse_loop($tag . '[].' . $key2, $value2, $i);
                        }
                    }
                } elseif (is_string($key) && !is_array($value)) {
                    $contents = str_replace($this->get_tag($tag . '.' . $key), $value, $contents);
                } elseif (!is_array($value)) {
                    $i = str_replace($this->get_tag($tag . '[]'), $value, $loop);
                }
    
                if(isset($i)) {
                    $parsed .= rtrim($i);
                }
            }
            return str_replace($t['b'] . $loop . $t['e'], $parsed, $contents);
        }
    
        function parse_cloop($tag, $array, $contents) {
            $t = $this->get_tags($tag, 'cloop:');
            $loop = $this->get_statement($t, $contents);
    
            $array['cases'][] = 'default';
            $case_content = array();
            $parsed = NULL;
    
            foreach($array['cases'] as $case) {
                $ctags[$case] = $this->get_tags($case, 'case:');
                $case_content[$case] = $this->get_statement($ctags[$case], $loop);
            }
    
            foreach($array['array'] as $key => $value) {
                if (is_numeric($key) && is_array($value)) {
                    if (isset($value['case'])) {
                        $current_case = $value['case'];
                    } else {
                        $current_case = 'default';
                    }
                    unset($value['case']);
                    $i = $case_content[$current_case];
    
                    foreach($value as $key2 => $value2) {
                        $i = str_replace($this->get_tag($tag . '[].' . $key2), $value2, $i);
                    }
                }
                $parsed .= rtrim($i);
            }
            return str_replace($t['b'] . $loop . $t['e'], $parsed, $contents);
        }
    
        function fetch($file_name) {
            $file = $this->base_path . $file_name;
    
            $fp = fopen($file, 'rb');
            if (!$fp) {
                return FALSE;
            }
            if(filesize($file) > 0) {
                $contents = fread($fp, filesize($file));
            } else {
                return $file_name . ' is empty.';
            }
            fclose($fp);
            return $this->parse($contents);
        }
    } 
?>

Parses a single ifstatement once, but just doesnt parse the loop now...

PHP error:
Warning: strpos(): Offset not contained in string. in /home/linkzor/public_html/test/template.class.php on line 71

Warning: strpos(): Offset not contained in string. in /home/linkzor/public_html/test/template.class.php on line 71

$15 via paypal for the one that comes up with an entire solution to this code... including the cases and loops... goto the btemplate website for documentation :P

i have work to do O.o i hate perl -_-
 
0
•••
I always use smarty... so I guess I don't help you writing that :) Buy Smarty is my favorite...
 
0
•••
0
•••

We're social

Unstoppable Domains
Domain Recover
DomainEasy — Live Options
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back