That should work fine in most cases. I usually handle my templates a little differently so I can have just a single template file with unlimited editable regions, making heavy use of the output buffer. Here's an overly simplified example of a page based on a template:
- Code: Select all
<?php
// build page-specific head content
ob_start();
?>
<title>My Page Title</title>
<link rel="stylesheet" type="text/css" href="styles.css" media="all" />
<script type="text/javascript" src="stufftodo.js"></script>
<?php
$headContent = ob_get_contents();
ob_end_clean();
// build page-specific body content
ob_start()
?>
<h1>My Page Heading</h1>
<p>Here's some fine body content.</p>
<p>[ <a href="wherever.php">Here is a LINK.</a> ]</p>
<p>Hwew's a footer or something.</p>
<?php
$bodyContent = ob_get_contents();
ob_end_clean();
// import the template and insert content
include('path/to/template.php');
?>
...and here's an overly simplified example of the template file:
- Code: Select all
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
<?php print($headContent); ?>
</head>
<body>
<?php print($bodyContent); ?>
</body>
</html>