A simple way for using templates in php new pages can run server side code or pretty much do anything you would normally want to do on a web page
First create your template.
cleary there is way more that can be done with this, I've kept it simple for demonstation purposes.
<?php
//page variables for output
//@@@@@@@@@@@@@@@@@@@@@
// $metaInclude
// $titleInclude
// $headInclude
// $bodyInclude
//@@@@@@@@@@@@@@@@@@@@@
?>
<!DOCTYPE html>
<html lang="en"><head>
<?php if (isset($metaInclude)) { echo $metaInclude; } else { ?>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name="keywords" content=""/>
<meta name="description" content=""/>
<?php } ?>
<?php if (isset($titleInclude)) { echo $titleInclude; } else { ?>
<title>Simple PHP Template</title>
<?php } ?>
<?php if (isset($headInclude)) { echo $headInclude; } ?>
</head><body>
<?php if (isset($bodyInclude)) { echo $bodyInclude; } ?>
</body></html>
Once your Template is completed you can begin to create new pages
<?php ob_start(); ?>
Hello World
<?php
$titleInclude = ob_get_contents();
ob_end_clean();
?>
<?php ob_start(); ?>
<h1>Hello World</h1>
<?php
$bodyInclude = ob_get_contents();
ob_end_clean();
require_once('template.php');
?>
A good old fashion "hello world" page
Create only the variables you want to use then simply include the template page and your done