How to Connect the Top, Bottom, and Middle of a PHP Template - dummies

How to Connect the Top, Bottom, and Middle of a PHP Template

By Steve Suehring, Janet Valade

When you are building a PHP template system, you start with the top of the page, and then create the bottom of the page. Weirdly enough, you leave the middle to the end. Here’s how you bring it all together.

The final classPage.php file should look like this:

<?php
class Page
{
public $type = "default";
public $title = "My Web Site";
public $titleExtra = ";
public function getTop() {
$output = ";
$output .= $this->_getDocType();
$output .= $this->_getHtmlOpen();
$output .= $this->_getHead();
$output .= file_get_contents("pageTop.txt");
return $output;
} //end function getTop()
protected function _getDocType($doctype = "html5") {
if ($doctype == "html5") {
$dtd = "<!DOCTYPE html>";
}
return $dtd . "n";
}
protected function _getHtmlOpen($lang = "en-us") {
if ($lang == "en-us") {
$htmlopen = "<html lang="en">";