Goodies to Go ™
May 5, 2003–Newsletter #231
This newsletter is part of the internet.com network.
http://www.internet.com
Featured this week:
* Goodies Thoughts – Including Easy
Maintenance
* Q & A Goodies
* News Goodies
* Goodies Peer Reviews
* Feedback Goodies
* And Remember This…
Goodies Announcement
Just in case you missed
it before, the new Beyond HTML Goodies book is now available!
Go beyond the basics
and learn how the pros add and use dynamic HTML features and advanced
JavaScript techniques. Beyond HTML Goodies demonstrates dozens of new and
different features readers can add to their existing Web pages using HTML and
JavaScript. The book starts with simple text and image tips, such as adding a
clock to a Web page or causing text to appear when the mouse moves over an
image. It gradually builds to more complex tricks, including manipulating forms
or working with cookies behind the scenes. Throughout the book, readers enjoy
Joe’s snappy style and “to the point” discussion of each “goody” in the book.
http://books.internet.com/books/0789727803
Goodies Thoughts – Including Easy
Maintenance
In last week’s newsletter we built a menu for a site that used the
window.setTimeout() JavaScript function to invoke code that enables the menu to
maintain its position in the viewable window, even as the page is scrolled up
and down (see https://www.htmlgoodies.com/letters). This is a very useful aid to
usability in a site, but may present a maintenance nightmare if it was featured
in each page on the site, and had to be changed on every page whenever the
navigation links within the site need to change. There is, of course, a way
around the problem. In fact, there are several, but this week I present a method
that uses "Server Side Includes" to hold the page headings, menu navigation bar
and page footings in individual files that are "included" in each page in the
site.
For the purposes of illustration, I have set up an example in the Upper
Lowerbury website (those readers who have been here a while will remember that
site, no doubt!). I have also put a copy of the individual pages at the bottom
of this newsletter (see "Goodies Footnotes", below) so that you can easily refer
to them. Viewing the source of the resulting page on the site doesn’t show you
where the breaks occur, nor does it show you the "include" instructions. These
copies show all. The address of the example is
http://www.upperlowerbury.com/menusample.asp
To use Server Side Includes (SSI), they must be enabled on the server that is
hosting the site. Most servers these days are configured to allow SSI, but if
you have any doubt, check with your service provider. If the server is running
Unix (or Linux or similar) with SSI enabled, any page can have an include
instruction. On a Windows system (NT, XP, 2000, 2003) includes are handled by
the ASP preprocessor (asp.dll). By default, the ASP preprocessor is invoked
every time the server delivers a page with a ".asp" extension. It will therefore
be necessary to name pages that have an include instruction with this extension.
In my illustration, which I have placed on a Windows 2000 server, I have named
all the pages this way including the "included" pages. This is for the sake of
my ease. It is only essential that pages which actually have the "include"
instruction follow this naming convention.
The format for an include instruction is as follows:
Enclosed in the quotes is the pathname and filename of the file to be included.
For good housekeeping purposes, I like to keep my "include"d pages in their own
directory, named here "ssi".
To accomplish our desired end, we first need three files, on each for the
Headings, Navigation and Footers. These three parts will then be "included" into
each page of the site. These are the files "head.asp", "nav.asp" and "foot.asp".
The header file contains all the page style information, the JavaScripts and
tag parameters we discussed last week, and the page header that is to
appear on each page. All this information is in this file alone, so changing it
once, right here, will affect every page in the site that uses this "include"d
file. I have added comments in the code to make it easy to tell where each
section of the resulting page (as seen, for example, with "View Source") came
from. This is a good idea for making life easier in the future!
The navigation file holds the menu, as we built it last week. It then starts a
table definition which includes a cell to create space for the menu (see last
week’s discussion) and then begins a cell which will contain the main body of
the page. Remember, this file will be "include"d in each page in the site, and
so the cell start will precede the content in that page.
The footer file holds the close of the main body table cell and row. In my
example, it then provides another table row that holds copyright information.
This information will now also appear in every page in the site that "include"s
this footer file.
The sample page I have provided illustrates the use of the "include" statements.
Notice that the content in this file doesn’t care that it is contained within a
table cell (the one started in the navigation file and ended in the footer
file.) In this page file we can lay out page elements however we want them. The
table that contains them will be wrapped around them when the page in rendered
to the site visitor. In my example, I have placed a bunch of paragraphs
containing the letter "a" so that the page will be long enough to show off the
place holding capability of the navigation menu.
At first, this example may seem to be a bit complicated, but if you look at the
various components, and at the resulting pages on the site, you should be able
to follow it easily enough. Once you get the hang of it, you will have mastered
a quite sophisticated technique for easy web site maintenance. By the way, there
is another example of a website that is constructed in this way. It is https://www.htmlgoodies.com
— check it out!
Thanks for Reading!
– Vince Barnes
Top
Q & A Goodies
Questions are taken from submissions to our Community Mentors. You can ask a Mentor a question by going to
https://www.htmlgoodies.com/mentors.
Q. I’m making a web page and for the menu I’m using a (menu.js) file to
be included into the page through javascript. However, this is not
working. I don’t know why because I’ve got it to work before. I’ve tested it on
geocities.com and also offline on my web browser.
(Another question, could the include file be in the form menu.txt or must it be
.js?)
Here’s the code:———-
menu.js
————
document.write("
- Introduction
- Functions of the Nervous System
- Components of the Nervous System
- Comparison Between Humans and Other Organisms
- Diseases that Affect the Nervous System
- Interaction of the Nervous System with Other Body Systems
- Conclusion
- Bibliography
- Glossary
Links According to Component
- Neurons
- Central Nervous System
- Peripheral NervousSystem
- Senses
- Sight
- Hearing
- Smell
- Taste
- Touch
————
i.intro.html
————
"http://www.w3.org/TR/html4/strict.dtd">
content="text/css"href="bio.css" type="text/css" rel="stylesheet"
System
src="include/menu.js">
< Home | Next >