Should I use a template engine?

Discussion in 'PHP' started by wwwbryan, May 2, 2009.

  1. #1
    I have my own mini-template thing like this:
    function template($content) {
    
    
     global $title;
     global $main;
     global $menu;
     global $userinfo;
       $filename = "./themes/theme.html";
       if(!$fd = fopen($filename, "r")) {
                    $error = 1;
            }
       else {
          $template = fread ($fd, filesize ($filename));
          fclose ($fd);
          $template = stripslashes($template);
          $template = eregi_replace("<% title %>", "$title", $template);
          $template = eregi_replace("<% main %>", "$main", $template);
          $template = eregi_replace("<% content %>", "$content", $template);
    	  $template = eregi_replace("<% menu %>", "$menu", $template);
    	  $template = eregi_replace("<% userinfo %>", "$userinfo", $template);
          echo "$template";
    	 
        } }
    
    function home() {
    
    global $title;
    global $main;
    global $menu;
    global $userinfo;
    Code (markup):
    Would that be good enough for a decently large php site or would it be better to use a template engine. Which I have no clue how to use (Ex. Smarty)
     
    wwwbryan, May 2, 2009 IP
  2. sapien

    sapien Peon

    Messages:
    15
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    if your project big enough try it. it to big for small projects
     
    sapien, May 3, 2009 IP
  3. yz4now

    yz4now Peon

    Messages:
    26
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    If your site is complex with a lot of pages and has a lot of traffic and stress on the server then I would go with something like Smarty because it has built in caching. If not then your template engine you made would work perfect.
     
    yz4now, May 3, 2009 IP