NamePros
Welcome, Guest! Ready to make a name for yourself in the domain business? We welcome both the hobbyist and professional domainer to join the discussion as part of the NamePros community.

Click here to create your profile to start earning reputation for posting, and trader ratings for buying & selling in our free e-marketplace. Build your trader rating with each successful sale. Our system has tracked over 100,000 sales and counting!
FAQ & TOS Register Search Today's Posts Mark Forums Read

Go Back   NamePros.com > Website Development Discussion Forums > Programming
Reload this Page What php template engine do you use?

Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics.

Advanced Search
2 members in live chat ~  


Closed Thread
 
LinkBack Thread Tools
Old 06-21-2005, 09:19 AM THREAD STARTER               #1 (permalink)
Account Suspended
 
axilant's Avatar
Join Date: May 2004
Location: /etc/passwd
Posts: 2,178
axilant is a splendid one to beholdaxilant is a splendid one to beholdaxilant is a splendid one to beholdaxilant is a splendid one to beholdaxilant is a splendid one to beholdaxilant is a splendid one to behold
 

Member of the Month
July 2005

What php template engine do you use?


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...
axilant is offline  
Old 06-21-2005, 09:27 AM   #2 (permalink)
NamePros Regular
Join Date: Mar 2004
Posts: 633
theparrot is a jewel in the roughtheparrot is a jewel in the roughtheparrot is a jewel in the rough
 



Well btemplate looks pretty light weight, but read http://www.massassi.com/php/articles/template_engines/ for some food for thought by its author.


There is one in pear you may want to take a look at as well if you are still looking after reading that article.
__________________
Need a break? Check out TheDamnBlog.com
Free $6.95 directi accounts at Directi Name Bin
Instant free $8.95 eNom accounts at Dncube.com
theparrot is offline  
Old 06-21-2005, 09:37 AM THREAD STARTER               #3 (permalink)
Account Suspended
 
axilant's Avatar
Join Date: May 2004
Location: /etc/passwd
Posts: 2,178
axilant is a splendid one to beholdaxilant is a splendid one to beholdaxilant is a splendid one to beholdaxilant is a splendid one to beholdaxilant is a splendid one to beholdaxilant is a splendid one to behold
 

Member of the Month
July 2005

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. And once i get it fixed, ill add-on to it...

Thanks for the nice read
axilant is offline  
Old 06-21-2005, 09:42 AM   #4 (permalink)
Senior Member
 
luxinterior's Avatar
Join Date: Jul 2004
Location: Kizmiaz
Posts: 1,088
luxinterior is a glorious beacon of lightluxinterior is a glorious beacon of lightluxinterior is a glorious beacon of lightluxinterior is a glorious beacon of lightluxinterior is a glorious beacon of lightluxinterior is a glorious beacon of lightluxinterior is a glorious beacon of lightluxinterior is a glorious beacon of light
 



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

Lux
luxinterior is offline  
Old 06-21-2005, 10:19 AM THREAD STARTER               #5 (permalink)
Account Suspended
 
axilant's Avatar
Join Date: May 2004
Location: /etc/passwd
Posts: 2,178
axilant is a splendid one to beholdaxilant is a splendid one to beholdaxilant is a splendid one to beholdaxilant is a splendid one to beholdaxilant is a splendid one to beholdaxilant is a splendid one to behold
 

Member of the Month
July 2005

Originally Posted by luxinterior
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

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 Code:
<?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) {
????: NamePros.com http://www.namepros.com/programming/100517-what-php-template-engine-do-you.html
                
$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(FALSETRUETRUETRUE);
            }
            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;
????: NamePros.com http://www.namepros.com/showthread.php?t=100517
    
            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($fpfilesize($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

i have work to do O.o i hate perl -_-
axilant is offline  
Old 06-21-2005, 10:43 AM   #6 (permalink)
Senior Member
 
dgaussin's Avatar
Join Date: May 2004
Location: France
Posts: 1,226
dgaussin is a splendid one to beholddgaussin is a splendid one to beholddgaussin is a splendid one to beholddgaussin is a splendid one to beholddgaussin is a splendid one to beholddgaussin is a splendid one to beholddgaussin is a splendid one to beholddgaussin is a splendid one to behold
 




I always use smarty... so I guess I don't help you writing that Buy Smarty is my favorite...
dgaussin is offline  
Old 06-21-2005, 11:00 AM   #7 (permalink)
NamePros Expert
 
Peter's Avatar
Join Date: Nov 2003
Location: Scotland
Posts: 5,074
Peter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond repute
 


Child Abuse Save The Children Save The Children Help The Homeless - Holiday 2009 Help The Homeless - Holiday 2009 Help The Homeless - Holiday 2009 Help The Homeless - Holiday 2009
i personally use the pear package HTML_Template_IT

http://pear.php.net/package-search.p...Search#results
Peter is offline  
Closed Thread


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools


Similar Threads
Thread Thread Starter Forum Replies Last Post
Googlism - What does google think of you? deadserious The Break Room 55 12-15-2005 09:09 AM

 
All times are GMT -7. The time now is 12:08 PM.

Domain name forum recommended by Domaining.com Powered by: vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.6.0 Ad Management plugin by RedTyger