2 Votes Vote

Text problem in template machine

Posted by topdog 359 days ago Questions| template file found All

I have this code:

class template
{
    public $template,$prefix,$replace;
    function __construct($template, $prefix)
    {
        $this->prefix = $prefix;
        $this->template = $template;
    }
    public function SetValue($name, $replace)
    {
        $this->replace["#".$name."#"] = $replace;
    }
    public function Tempclude($found) 
    { 
        $file = "styles/main/".$found[1].'.html';

        if(!file_exists($file))     
            exit("the template '" . $found[1] . "' wasn't found."); 
        return file_get_contents($file); 
    }
    public function finish($stream = "normal")
    {
        if($stream == "folder")
            $code = file_get_contents("../styles/main/".$this->template.".html");
        else 
            $code = file_get_contents("styles/main/".$this->template.".html");

        $code = preg_replace_callback("@<pb:include=\"(.*)\">@iuU", array($this, 'Tempclude'), $code);

        if(is_array($this->replace))
            $code = str_replace(array_keys($this->replace), $this->replace, $code);

        $code = str_replace("\r\n", "", $code);
        $code = str_replace("   ", "", $code);
        echo $code;
    }
}

If I type in the Template some simple text, the page turns white with nothing inside.

What is the problem?

Originally asked by: Rafi on Stack Overflow

Discuss Bury


Who Voted for this Question