Jump to content

Multiple Html Files With Same Header, Footer


ABA

Recommended Posts

I am fairly new with HTML. I am trying to create a web site that has multiple HTML files that correspond to multiple pages on the web site. Many of these files have the same header, footer and other HTML code that needs to be duplicated in all the files. Is there a way by which I can have this common code in place and is referenced by multiple files; so that I don't have to make changes in all places.

Link to comment
Share on other sites

Whatever you do, don't use frames. That's the way we did it 12 years ago, but it's no longer considered good practice. Run away from anyone who tells you different.The ideal solution is to use a server-side language to pre-process your documents. A lot of us here use PHP, but any language will do. Specifically, you want to use an include function. This essentially grabs the contents of an external file and pastes them into your main file before sending it along to the browser. The beauty of included files is that they are not complete HTML documents. They only need enough code to create the header/footer/menu or whatever it is.Here is a PHP statement that would include a header file:<?php include 'header.php'; ?>Put it exactly where you want the header to appear.It's really that simple.Most hosts make PHP available; some do not enable it by default. If you try this and it doesn't work, write back.

Link to comment
Share on other sites

You don't have to know PHP. The code snippet I gave you is everything you need to know. Really. Everything.In any case, there is no HTML solution. There are workarounds, but they are much more complex than the PHP solution I showed you.The only problem with the PHP solution is that you cannot run it on your desktop. It requires the PHP interpreter installed on your server. So you'll have to put the documents you are working with on your server, if they are not already there.On the other hand, I have no idea what Coffee Cup does or does not do. I can't imagine an editor that would not let you add your own markup, but maybe I'm wrong.Consider this: My response sat on the board all night, and no one else added another response. That wasn't blind luck. Synook, boen_robot, and Ingolme all came by and had a look. They have each made thousands of posts on this board, but they had nothing to add. What I described is what everyone does.

Link to comment
Share on other sites

There are two functions: include() and require().Include will throw an error if the file isn't found but the rest of the program will keep excuting. Require will throw a fatal error if the file isn't found, which prevents any further scripts from executing.About include_once() and require_once(), it only includes the file if the file hasn't already been included.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...