Jump to content


PHP Templates


1 reply to this topic

#1 hk_

    Young Padawan

  • Members
  • Pip
  • 52 posts
  • Gender:Male
  • Location:lost

Posted 02 August 2008 - 08:13 AM

Hi for starters , i'm just updating a template script that i found quite some time now.
it loads the template file but it doesn't return the [Tags not found] error when loaded.

template.class
<?php

class tpl_engine{

public $themme;

public function tpl_engine($tpl){
 if(file_exists($tpl)){
  $this->themme = implode("",file($tpl));
 }else{
  exit("<script>alert('The $tpl file wasn\'t found!');</script>");
 }
}

public function load($file){
 ob_start();
 include($file);
 $disp = ob_get_contents();
 ob_end_clean();
 return $disp;
}

public function parse($tags){
 if($tags > 0){
  foreach($tags as $tag => $data){
   $ctrl = (file_exists($data)) ? $this->load($data) : $data;
   $this->themme = str_replace("{".$tag."}" , $ctrl , $this->themme);
  }
 }else{
  exit("<script>alert('There\'s no tags for replacement!');</script>");
 }
}

public function display(){
 print $this->themme;
}

}
?>


index.php
<?php
require_once("lib/template.class");

$temp = new tpl_engine("themmes/default/template.tpl");

$temp->parse(array(
 "title" => "titulo",
 "header" => "themmes/default/header.tpl"
 ));

$temp->display();

?>

the error is in the parse() function if() statement , i have triyed like a hundred fuctions
to return the value but it just dont like me!

thanks by the way!

#2 rc69

    PHP Master PD

  • P2L Staff
  • PipPipPipPip
  • 3,827 posts
  • Gender:Male
  • Location:Here
  • Interests:Web Development

Posted 02 August 2008 - 01:28 PM

Looking at your code, there is no reason it should be printing the error message. You do have tags set to be replaced.

The only obvious error i would like to point out is the following line:
if($tags > 0){
$tags is an array, so it should be
if(count($tags) > 0){






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users