Untangling Spaghetti HTML

Written by Sunil Tanna


Untangling Spaghetti HTML ========================= by Sunil Tanna, EBookCompiler.com

When I was first learning to write computer programs, one ofrepparttar most important points that was drummed into me was that it's never a good idea to write great chunks of computer code that are repetitions of earlier code. The reason is simple: when it comes time to updaterepparttar 134573 code, you'll have a tough time makingrepparttar 134574 same change in each copy, and you'll have an even tougher time making sure that each changed copy has been modified inrepparttar 134575 same way.

Why this digression into programming lore? If you create web sites , there is a good chance that, at least most ofrepparttar 134576 time, you don't think of your HTML files as "computer code". You probably think of them as content, documents, my writing... etc. Butrepparttar 134577 truth is they are. You need only open an HTML file in a plain text editor, and you can seerepparttar 134578 HTML language.

Sorepparttar 134579 question is, canrepparttar 134580 same spaghetti problem arise with HTML code? If you've been a webmaster for a while, you probably already knowrepparttar 134581 answer... absolutely. The typical web site contains lot of repeated elements.

For example, you may haverepparttar 134582 same heading or footer on each page. You might have a search box or banner code on each page. You might haverepparttar 134583 same menu downrepparttar 134584 side.

Updating all these multiple copies ofrepparttar 134585 same HTML code in different files quickly gets tiresome. Even if you haven't encounteredrepparttar 134586 update-problem yet, as your projects grow larger and larger, you soon will.

HOW TO AVOID SPAGHETTI?

One answer isrepparttar 134587 various "include" mechanism that HTML technologies provide:

1. Server Side Includes (SSI)

This technology is implemented on many web sites, and basically allows you to include a common fragment of HTML code (stored in a separate file) into as many HTML pages as you want. The advantage is that instead of updating each file individually, you only need updaterepparttar 134588 common fragment once.

Here's how:

* On most web servers, you simply rename your HTML files (the ones that are doingrepparttar 134589 including) with a .shtml extension.

* Where you want to includerepparttar 134590 common fragment of code use a line like:

[!--#include file="fragment.html" --]

IMPORTANT: Because some email programs don't display greater-than and less-than signs properly, I've used square brackets, but when you copy this line make sure to changerepparttar 134591 brackets to greater-than and less-than signs. If you prefer to seerepparttar 134592 code online, (and displayed correctly), go to: http://www.suniltanna.com/spaghetti.html

2. ASP Includes

For NT web servers, in .asp pages, you canrepparttar 134593 exact same include syntax as for SSI.

3. PHP Includes

If your web site supports PHP (a script language that runs onrepparttar 134594 server), another way to achieverepparttar 134595 same thing is to userepparttar 134596 PHP include command.

Here's how:

* Rename your HTML files (the ones that are doingrepparttar 134597 including) with a .php extension.

* Where you want to includerepparttar 134598 common fragment of code use a line like:

[?php include 'fragment.php' ; ?]

IMPORTANT: Againrepparttar 134599 same point aboutrepparttar 134600 brackets applies. If you prefer to seerepparttar 134601 code online, (and displayed correctly), go to: http://www.suniltanna.com/spaghetti.html

NO THROUGH ROAD HITHER?

Right, so this all sounds fantastic, problem solved?

Not so fast... While these are powerful techniques they also have drawbacks and limitations:

1. Most web design programs don't know anything about these types of includes. This means you have to work in a text editor on repparttar 134602 raw HTML code, manually chopping up your files into fragments, and insertingrepparttar 134603 include commands intorepparttar 134604 HTML code. Worse yet, once you've done it, it's quite possible your web design program won't allow you to make any further changes.

Using SSI's to Ease Site Maintenance

Written by Lauri Harpf


Before building a site, every webmaster has to make a decision on what layout method to use. Most seem to go with either a frame or a table-based layout,repparttar latter being more popular in these days. While both of these have their advantages and disadvantages, a frame-based site is usually easier to update. If you happen to have a 200-page site withrepparttar 134572 same navigation on every page, adding one link torepparttar 134573 navigation menu might require you to edit all ofrepparttar 134574 pages ifrepparttar 134575 design is built with tables. Onrepparttar 134576 other hand, ifrepparttar 134577 site uses frames, you can get by with changing just a few files and save yourself a lot of time.

No, I'm not trying to convince you to switch to frames. I myself use tables and am not going to change my layout. The only problem is that over time, sites tend to grow. It just might be possible to edit around 20 pages when you want to change something, but when we start talking 50 or over one hundred, it just doesn't seem like a good idea. Unless you are prepared to spend hours trying to keep your navigation menu up to date, you have to come up with a better way of doing things.

SSI's torepparttar 134578 Rescue ===================

If your host supports Server Side Includes and is running Apache, you can use this article to make your table design as easy to maintain as it would be if you were using frames. The best part is that visitors won't even notice that you have changed anything. Afterrepparttar 134579 new system is in place, they will see exactlyrepparttar 134580 same design and HTML code as before, but you will be saved from hours of monotonous work.

Server Side Includes, or SSI's, can be used in many ways. With them you can execute CGI programs, displayrepparttar 134581 current date & time on your page and do plenty of other things as well. In this article, we use them for including external files to your HTML. The idea is to create a separate file from your navigation menu and use SSI's to point to it, requiring you to merely edit one file when you wish to changerepparttar 134582 navigation.

Should you have some knowledge of Server Side Includes, you might be a little worried. Doesn't this require that you rename all your pages from ".html" to ".shtml" if you want it to work? That would take a lot of time, breakrepparttar 134583 links that are pointing to your site and you might have to resubmit your pages torepparttar 134584 search engines. Is it reasonable to go through all that trouble to make maintaining your site a little easier?

Cont'd on page 2 ==>
 
ImproveHomeLife.com © 2005
Terms of Use