| Languages Used |
XHTML PHP CSS |
Now to see how to code the content pages in a PHP master page environment.
1. This is going to assume that you have already gone through and created a
master page.
2. The first step in a content page is to tell the server that it is PHP, and to call a function called
ob_start. This function is an output buffer. For more info click
here.
CODE BLOCK 1
<?php
//Buffer larger content areas like the main page content
ob_start();
?>
3. Next we add all of our content. You can use any code you would like in here, just DO NOT put any HTML, HEAD, or BODY tags in this sections. Those will all be pulled from the master page.
CODE BLOCK 2
<div id="maincol" >
<!-- Place holder for all of our content -->
</div><!-- end maincol -->
4. Now the next step is to assign all of this content to a variable, give our page a title, and call the
master.php.
CODE BLOCK 3
<?php
//Assign all Page Specific variables
$pagemaincontent = ob_get_contents();
ob_end_clean();
$pagetitle = "Title text";
//Apply the template
include("master.php");
?>
5. That is it. Now you have a page which will call the master.php, and the only thing it has in it is a page title, and content. NOTE - Save this as a template, and remember to change the content, and page title for every page you create, and do a SAVE AS.