[Home]Include one file in another

HomePage | RecentChanges | Preferences | Newbie Help

Category HTML FAQ -:- Category SSI FAQ -:- [Category JavaScript FAQ]? -:- Category PHP FAQ

HTML Preprocessing

This is where a program takes some source files and combines them to form the website before they are uploaded to the webserver.

See also: http://html-faq.com/utilities/?htmlpreprocessor

On Wed, 7 Mar 2001 13:00:51 -0500, "Chris Beall" <Chris_Beall@prodigy.net> wrote on alt.html

A third alternative is a pre-processor. You create source HTML with special commands such as "#include chunk.html", then run the preprocessor against your source files. The preprocessor recognizes the command and finds chunk.html, which it copies inline into the source file, generating a new output file that contains the imbedded chunk. A preprocessor can do many other useful things as well. The advantage is that you run the preprocessor ONCE (for each update of your site) and upload the output files to the server. No server support is required and there is no performance exposure, since the preprocessor output is not dynamically created at page-fetch time. The only down-side is a bit more administrative effort on your part (separate directories and perhaps filetypes for source and output).

Some free preprocessors

Server Side Includes

On Wed, 7 Mar 2001 13:00:51 -0500, "Chris Beall" <Chris_Beall@prodigy.net> wrote on alt.html It appears that all you want to do is be able to "include" a chunk of source code that you use in many places, thus allowing the chunk to be maintained in only one place.

SSI, recommended by others, performs this function on the server, each time the page is fetched. This requires that the server have SSI support and that you have access to that support. If you use this and later move from one server to another, you may have to make changes in your code, such as changing the filetype from .html to .shtml, depending on the requirements of the new server.

Server Side Scripting


Another server-side solution is to use PHP (http://php.net/). Includes are called by inserting the following code in the html document (at the appropriate place): <?php include("file.ext"); ?> (file.ext being the name of the file to be included). The main html file has to be given an extension which will be parsed, usually *.php or *.php3. [quick intro to php]

Dylan_Parry adds: PHP4 introduced the "require" command. This means that regardless of what "if" statements or conditions you use in your code, the file will always be included. Just use <?php require("file.ext"); ?>, the same as above.

See also PHP FAQs.

are there any "internal wiki-links" to point to instead of the one above?

Jerry Muelver Not yet. Most of the PHP FAQs are answered by external links. We haven't acquired a hot PHP maven to write up our own explanations yet.

Mark Gallagher Ahhh, give me time. I mean, it only took a year or so for me to become **really** proficient in HTML, and PHP isn't **that** much more complicated, right? Right? :o)


Very simple, just <!-- #include file="nameoffile.inc" -->, or if you are concerned about security <!-- #include file="nameofile.asp" -->.

People often ask whether it is possible with ASP to do conditional includes - the answer is yes and there are a few ways to do it.

1. Using If statements

   <% if condition then %>
   <!-- #include file="thisfile.inc" -->
   <% else %>
   <!-- #include file="thatfile.inc" -->
   <%end if%>

2. Using Select

   <% select case variable
   case "condition1"
   <!-- #include file="condition1.inc" -->
   <% case "condition1" %>
   <!-- #include file="condition2.inc" -->
   <% case else %>
   <!-- #include file="conditionelse.inc" -->
   <% end select %>

Yes, you can also include files within include files.


Other languages can also be used, but nobody has added details to this Wiki yet.


Try IFRAME, if you don't mind losing old NS browsers, and having the many Problems with using frames. You could also use normal frames.


Using the OBJECT tag with a type attribute of text/html will give similar results to an IFRAME, but will be valid in Strict (X)HTML as well. Support for OBJECT is very bad in older browsers, so this method is best used only in controlled conditions where the browsing environment can be known with certainty.

Client Side Scripting

An external JavaScript file filled with document.write lines can work in some circumstances. Unfortunatly this makes the content in accessible to user agents without JavaScript (including GoogleBot)

On Wed, 7 Mar 2001 13:00:51 -0500, "Chris Beall" <Chris_Beall@prodigy.net> wrote on alt.html

JavaScript was another suggested option, but JavaScript is unavailable on about 15% of browsers and, like SSI, inserts computation time into every page-fetch.

HomePage | RecentChanges | Preferences | Newbie Help
This page is read-only | View other revisions
Last edited August 9, 2003 10:03 pm (diff)

This FAQ is happily hosted by Betadome Digital Media