I use phplib - however the version I got from their web (ages ago) was buggy, so I'll attach an alternaitve to this post.
I use them to
1) create web pages
2) create html emails
really useful. Obviously you end up with a greater number of files but the tradeoff in maintainability is worth is.
In this example I am changing the product name depending on the choice made by the user. The html keywords have a standard set and then additional words depending on the choice. And the choice will also determine the stylesheet attached to the file. This change may be made on the choice, or information fed back about the users browser, screen size etc.
The important thing to remember is that you are using building blocks to create an html text block on the browser. The browser doesn't care how it got there just so long as it makes sense.
example template:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>{PRODNAME} :: {TITLE}</title>
<meta name="blah, blah, blah, {KEYWORDS}">
{AGENTCSS}
</head>
<body>
Welcome to the website of {PRODNAME}
</body>
</html>
then my php has
<?php
include_once("template.inc");
$t = new Template();
switch ($choice){
case "info":
$keywords = "trial,software,accounts";
$htmfile = "product_info2.htm";
$title = "learn about the advantages of using " . $agentvars["prodname"];
$needjs = true;
break;
case "free_trial":
$keywords = "trial,ledger,owner";
$htmfile = "freetrial.htm";
$title = "Download a free demo trial version";
break;
}
//set up the files I need
$t->set_file( array( "HeadGen" =>"headgen.htm",
"HeadImg" =>"headimg.htm",
"Body" $htmfile
));
//set up the variables in the template
//this is a subset to give an idea
$t->set_var( array("PRODNAME" => $agentvars["prodname"],
"AGENTCONT" => $agentvars["contact"],
"IMGDIR" => $agentvars["imgdir"],
"KEYWORDS" => $keywords ));
$t->parse("Output", "HeadGen");
$t->p ("Output");
?>
My webpages have sections, the top banner, the mid section and the bottom banner. I use the same code to call the top banner everytime so I have it separate from the mid section. This means that if I make a change I make it once and all the pages see the change. If I coded the menus etc into each page a change would take me ages to implement. The other way would be to have the menu's in frames but that's another argument 🙂
I hope this helps