An example of a template system in PHP
All formating (of the web page) is omitted, but easily added as CSS controls from another echoContent($filename) inserted in the html head.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
SYSTEM "http://www.w3.org/TR/xhtml11/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<!-- classic 'use if desired meta data;
notice "==TEMPLATE==" to remind you to edit
on a per-page basis
-->
<title>Tech-101.com: ==TEMPLATE==</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<meta http-equiv="content-style-type" content="text/css" />
<meta http-equiv="content-language" content="en-us" />
<meta name="title" content="==TEMPLATE==" />
<meta name="description" lang="en" content="==TEMPLATE==" />
<meta name="keywords" content="==TEMPLATE==, , , " />
<meta name="category" content="general" />
<meta name="robots" content="index,follow" />
<meta name="distribution" content="global" />
<meta name="copyright" content="==TEMPLATE==" />
<!-- end meta -->
<!-- user php function to fetch raw html or other php files
to be shown on THIS page
-->
<?php
function echoContent($filename) {
if ($theData = file_get_contents($filename, FALSE)) {
echo "$theData";
} else {
echo '<span class="ERR">Error opening source file :(\n</span>'; # $filename!\n";
}
}
?>
</head>
<body>
<?php
<!-- this would include a common HEADER
from the parent directory of the site.
This might be the look-n-feel CSS or other common presentation
-->
echoContent("../siteHeader.html");
<!- this would include a common MENU system for the site
as shown here, as a common 'banner' across
the top of every page.
A two column presentation (menus left, body text right)
would only need a change in this template to
implement a table, row, two cells or
a frameset with two frames
-->
echoContent("../siteMenus.html");
<!-- every page should have it's own h1
using CSS to center h1's would be simple
-->
echo "<H1>==TEMPLATE==</H1>";
<!-- now we fetch the body presentation itself
-->
echoContent("pageContent.html");
<!-- and a common site footer
perhaps, copyright, and site-common links
eg: about_us, contact_us, terms_n_conditions
-->
echoContent("../siteFooter.html");
?>
</body>
</html>