Jump to content

my template class


chriscloyd

Recommended Posts

this is the error im getting
Parse error: parse error, unexpected $end in C:\xampp\xampp\htdocs\template.php(54) : eval()'d code on line 11
and my code is here
[code]<?php
class TemplateEngine
{
    var $Template;
    var $TemplateExt = '.tpl';
    var $TemplateDir = 'templates/';
   
    function SelectTemplateFile($file, $error_line = 0, $error_file = '')
    {
        if(is_dir($this->TemplateDir))
        {
            if(!file_exists($this->TemplateDir.$file.$this->TemplateExt))
            {
                $error = "<b>File:</b> ".$error_file."<br/>
                <b>Line:</b> ".$error_line."<br/>
                <b>Date:</b> ".date("D M j G:i Y&quot;")."<br/><br/>
                Error loading ".$this->TemplateDir.$file.$this->TemplateExt.", file does not exist.";
                return die($error);
            }
            elseif(file_exists($this->TemplateDir.$file.$this->TemplateExt))
            {
                return $this->Template=file_get_contents($this->TemplateDir.$file.$this->TemplateExt);
            }
        }
        elseif(!is_dir($this->TemplateDir))
        {
                $error = "<b>File:</b> ".$error_file."<br/>
                <b>Line:</b> ".$error_line."<br/>
                <b>Date:</b> ".date("D M j G:i Y&quot;")."<br/><br/>
                Error opening ".$this->TemplateDir.", directory does not exist.";
                return die($error);
        }
    }
    function ReplaceVars($vars=array(), $error_line = 0, $error_file = '')
    {
        if (sizeof($vars) > 0)
        {
            foreach ($vars as $var => $content)
            {
                $this->Template=str_replace("{".$var."}", $content, $this->Template);
            }
        }
        else
        {
            $error = "<b>File:</b> ".$error_file."<br/>
            <b>Line:</b> ".$error_line."<br/>
            <b>Date:</b> ".date("D M j G:i Y&quot;")."<br/><br/>
            Error no tags destined for replacemnt.";
            return die($error);
        }
    }   
    function Compile()
    {
        eval("?>".$this->Template."<?php");
    }
}
?>[/code]
Link to comment
https://forums.phpfreaks.com/topic/30393-my-template-class/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.