I am trying to write a lightweight templating system.
inc/header.php:
require_once ("inc/template.php");
$template = new template;
$template->tpl("header.tpl");
$template->assign("CONTENT", "this is the CONTENT of the header");
$template->display("header.tpl");
inc/template.php:
( please excuse all my comments 🙂 )
<?
class template{
var $tplfile;
function tpl($file){
if (!file_exists("templates/$file")) {
echo "The needed TPL file; $file , does not exist.";
die();
}
$template->tplfile = $file;
echo $template->tplfile;
echo $file;
}
function assign($tag, $content){
// tag array
// content or replacement array
$tag = array();
// we need to know how many assigns' we've already done, or else we'll overwrite our array's!!
$tag[$i] = $content;
// we save the $tag array for later use in the display function
}
function display(){
echo $template->tplfile;
echo $file;
if (isset($x)){
echo "hello world, tpl file checks done okey, lets go for the page...";
// get file name
// check file exists
// does exist
// great, continue.
// doesnt
// ECHO : TPL file does not exist
// DIE
// find content in brackets
// see if we have a php tag for the hard tpl content
// we do
// set tag array [$i] to content or replacment array [$i]
// build our block of text ?
// dont, we ignore it, maybe issue a warning for the TPL developer
// dump it all out onto a page
} else {
echo "TPL not set. <br><br>Cant create template. This is a programming error.";
}
}
}
?>
when I call $template->tpl; it correctly assigns $tplfile from $file, and prints $template->tpfile. However, when I try to get it again, in the $template->display function, it returnas absolutly nothing, as if it was blank. I dont understand how it can work in the tpl function, and not in the display function.