Templating Engine
Posted: Fri May 21, 2004 4:59 pm
Ok, so, I've been hired/volunteered to redo a site's coding from scratch. Right now it works fine, but when you look at the code, it's html/php/javascript all jumbled together in huge, unnecessary files (about 400 at last count).
First thing I'm thinking of is the templating engine. I've been bouncing ideas around, but I have no one to bounce them off but myself, and I just keep trying to find a better way, and I can't really think of it.
Here's a few file ideas:
1.inc (template 1):
index.php:
functions.php:
Ok, so can anyone give pointers for where to go next with this, how to improve it, how to print out the page, opinions on the method im using, etc..?
Thanks a lot.
By the way, I'm not in a rush, so please try to give me as much information as you can about this, thanks
First thing I'm thinking of is the templating engine. I've been bouncing ideas around, but I have no one to bounce them off but myself, and I just keep trying to find a better way, and I can't really think of it.
Here's a few file ideas:
1.inc (template 1):
Code: Select all
<html>
<head>
<title><?php echo $title; ?></title>
<link rel="stylesheet" type="text/css" href="incs/style.css" />
<script language="javascript" src="<?php echo $js; ?>"></script>
</head>
<body>
<div id="main_container">
<div id="header"><?php echo $header; ?></div>
<div id="left">
<div id="nav"><?php echo $nav; ?></div>
<div id="ads"><?php echo $ads; ?></div>
</div>
<div id="middle">
<div id="main_contents"><?php echo $contents; ?></div>
<div id="top5"><?php echo $top5; ?></div>
</div>
<div id="right">
<div id="stats"><?php echo $stats; ?></div>
</div>
</div>
</body>
</html>Code: Select all
<?php include("functions.php");
if(empty($_GET['p'])) $p = "home";
$html = new Page();
$html->build($p);
$html->print();
?>Code: Select all
<?php class Page {
var nav;
var ads;
function build($p){
include("tpls/" .$user[tpl]. ".inc");
eval($page); //would be in Page->print();
//this is where I'm stuck, this code won't work.. because it doesn't evaluate the php AND parse the html.. :\ am i better to just do a str_replace of [ads], [nav], etc, and then echo it out?
}
function vars(){
$result = mysql_query("SELECT * FROM site_links");
while($row = mysql_fetch_array($result)){
$this->nav .= "<a href="" .$row[link]. "">" .$row[name]. "</a><br />";
}
$this->ads = include("incs/ads.txt");
}
}
?>Ok, so can anyone give pointers for where to go next with this, how to improve it, how to print out the page, opinions on the method im using, etc..?
Thanks a lot.
By the way, I'm not in a rush, so please try to give me as much information as you can about this, thanks