I’m trying to catch up with modern website design, going all fancy with CSS and XHTML compliance. So far, so good.
Now I’m setting up a standard design with a menu on the left hand side of the screen, which should be the same on every page of the website. Tou know the drill: menu item 1: blah, menu item 2: blah squared, etcetera.
I have put the style definitions in a separate .css file, but I can’t figure out whether there is a way to put the content in a separate ‘sub’-file as well.
I can of course simply copy the content for the menu items into every page, but if I want to modify the links this will become a hassle. I could use frames, but I’ve learned that you shouldn’t use those if you can avoid it at all. What I’m really looking for is a way of ‘linking’ a sub-HTML file in the same way as I can link a style sheet.
So is there some way to do this, or am I simply out of luck?
You can do it with an iframe. Frame purists will still recoil at this, because it has “frame” in the name, but iframes do not have all of the problems that frames do. For instance, the URL of your page will work like you expect.
If you refuse to use frames and iframes, there’s no way to do it with straight-up HTML, but of course, lots and lots of people do it with server-side includes.
Don’t use an iframe for a menu! Argh! I don’t think they show up at all in some versions of Netscape, and it may be worse even than that.
Use Server Side Includes (SSI) as suggested by Kinthalis, but these have to be set up as a special feature on your webhost server. It shouldn’t be too difficult to arrange.
I have to have the same menu colour-coordinated on several different sections of my site, so I use Includes for the non-colour-dependent sections and that way I only need to change one text file to adjust every menu on the site.
Really, I have no big thing for iframes. I’ve never even used them. But they are standard HTML, and they do what you want. I also remember now that the OBJECT tag allows you to do what you want. Here’s the HTML 4.01 411 on embedding documents.
I don’t have a cite, it was through practical experience. But it was about 18 months ago that we tried it, and now I can’t remember if it was actually Netscape that was the problem. It may have been another browser.
Okay, that’s fine. I’m just saying it’s possible the iframe wasn’t the problem. That happens a lot with HTML. You can’t get something to work in a browser, and it turns out to be something you totally didn’t expect. Anyway, if I were the OP, I would consider the following solutions in the following order:
[ul]
[li]Server-side includes (including ASP or PHP)[/li][li]Copying and pasting it yourself (what I did)[/li][li]Iframes[/li][li]Objects[/li][li]Frames[/li][li]Javascript (not generally bad, but certainly not ideal for this application)[/li][/ul]
Most good programmer-type editors (not text editors) can do global changes across a whole set of files, so this isn’t really that much of a hassle anymore.
I’ll check out that Server Side Include/PHP thingy. I’ve seen the term before, but didn’t know what it could do.
Maybe I’ll also follow t-bonham’s advice and shell out real money for a real editor. Up to now I kept working with Notepad; I’m one of those people who started programming in hex and has an innate distrust of the quality of code of automated tools. However, I see this could save a lot of time if I have to make many changes in the future.