I put two include statements in each file, one at the top and one at the bottom. Like so:
Main contents and code
That's it. I create my layout and then I look for the large part of the layout where the main content would go, this gives me my "dividing" line. All code above this goes in the templateTop, all code below it goes into templateBottom.
I have a page, with a menu across the top, some content and a footer. This is how my html might look.
Hello and welcome to the grand site of ....
This goes into the top
This goes into the bottom:
There is one drawback to this method, if you use images or have referential links within your template files, they could have the wrong url because your base will always be the file that did the include.
For example, if you have the following line in your template file.
The root of the file included the template will be included with this:
When the file index.php has the include:
But when the file /actions/buyItem.php has the include:
To fix this you must always use fully qualified paths or refer to the root by have a "/" in the front of all referential urls.