HTML Wrapper
No self respecting webmaster anymore wants to sit down and edit hundreds of HTML pages when they add a new item to their menu. For years, frames were the answer to this, so that coders could only change the infromation that was vital to their page. But anymore, frames are being frowned upon as well, and it’s just a sign of the times. People want a flat page, that doesn’t break the “Back Button“, yet the web designer still wants a method by which they can easily edit things in 1 location, and have it take affect on all pages.
So along came PHP, which offered many advances for the common webmaster, yet a lot of people were afraid of it because it made them “really code” their websites! Afraid you should not be! With the power of PHP, you can have a very easy to edit page, and you don’t even have to do much more than you were doing with frames! There are a couple drawbacks of course, like most free servers don’t have PHP support, but for anyone who has space with PHP support, it’s a gem and once you start, I can almost guarentee you won’t go back.
So, by “HTML Wrapper”, I mean we’re going to literally “wrap” your content around in a virtual blanket. What does this do for you? You can change the blanket (which will control the look, the feel, etc) while still warming the same person (or displaying the same data). Here’s how:
The first real step in doing this is to design your website. Though, I’m assuming you have done this already, otherwise you wouldn’t be looking at how to change it to be in a wrapper. So for this example, I’m going to create a dummy page, and here’s the code for that page:
<HTML>
<head><title>My Dummy Page</title></head>
<body>
<ol>
<li>My Menu</li>
<li><a href=”/index.php”>Menu Item 1</li>
<li><a href=”/page2.php”>Menu Item 2</li>
</ol>
My Content!<br />
What do you think?
<p>
Copyright Me 2003
</body>
</html>
So now lets start the process of making this into a wrapped content page. First step is to identify where the content is on the page. In this case, it’s located where the following text is:
My Content!<br />
What do you think?
Now, everything before that we’ll refer to as our header, and everything after that we’ll refer to as our footer. So, we split this page up into 3 pages like such:
header.php:
<HTML>
<head><title>My Dummy Page</title></head>
<body>
<ol>
<li>My Menu</li>
<li><a href=”/index.php”>Menu Item 1</li>
<li><a href=”/page2.php”>Menu Item 2</li>
</ol>
inc/main.php:
My Content!<br />
What do you think?
footer.php:
<p>
Copyright Me 2003
</body>
</html>
So now we have the following files:
- header.php
- footer.php
- inc/main.php
And we can arrange them in a single PHP file to recreate the previous page like this:
<?php
include(“header.php”);
include(“inc/main.php”);
include(“footer.php”);
?>
And if we save that as index.php, whenever someone comes to my site, they’ll see it just as though it was still the single page. So what’s the advantage to doing this? Well, we’ve got a couple prime advantages, first of which now we can edit header.php or footer.php and change the whole lookout of the site, as the layout isn’t bound by the content. Also, if say we want an “about me” page, that’s very easy to do as well by simply making aboutme.php like such:
<?php
include(“header.php”);
include(“inc/about.php”);
include(“footer.php”);
?>
So all of the content for the new page is in inc/about.php and we’ve still not had to re-do everything that’s in the header or footer. Definately a time saver, and worth your time to check out!
Enjoy.
No comments yet. Be the first.
Leave a reply