Reusing Content with Templates and Libraries > Using server-side includes

 

Using server-side includes

Server-side includes are instructions to the server to include a specified file in the current document before sending the document to the user who requested it. (You can think of it as something like a library item that's provided by the server.)

When you open a document that's on a server, the server processes the include instructions and creates a new document in which the include instructions are replaced by the contents of the included file. The server then sends this new document to your browser. When you open a local document in a browser, however, there's no server to process the include instructions in that document, so the browser opens the document without processing those instructions, and the file that's supposed to be included doesn't appear in the browser. It can thus be difficult, without using Dreamweaver, to look at local files and see them as they'll appear to visitors after you've put them on the server.

With Dreamweaver, though, you can preview documents just as they'll appear after they're on the server, both in the Design view and when you preview in a browser. To display included files, Dreamweaver uses a translator to mimic the way a server would process the include instructions.

Placing a server-side include in a document inserts a reference to an external file; it doesn't insert the contents of the specified file in the current document. Dreamweaver displays the contents of the external file in the Document window, making it easier to design pages, but you cannot edit the included file directly in a document. To edit the contents of a server-side include, you must directly edit the file that you're including. Any changes to the external file are automatically reflected in every document that includes it.

There are two types of server-side includes: Virtual and File. Choose which to use depending on what type of Web server you use:

If your server is an Apache Web server, choose Virtual. (This is the default choice in Dreamweaver.) In Apache, Virtual works in all cases, while File works only in some cases.
If your server is a Microsoft IIS server, choose File. (Virtual works with IIS only in certain specific circumstances.) Unfortunately, IIS won't allow you to include a file in a folder above the current folder in the folder hierarchy, unless special software has been installed on the server. If you need to include a file from a folder higher in the folder hierarchy on an IIS server, ask your system administrator if the necessary software is installed.
For other kinds of servers, or if you don't know what kind of server you're using, ask your system administrator which option to use.

Some servers are configured to examine all files to see if they contain server-side includes; other servers are configured to examine only files with a particular file extension, such as .shtml, .shtm, or .inc. If a server-side include isn't working for you, ask your system administrator if you need to use a special extension in the name of the file that uses the include. (For example, if the file is named canoe.html, you may have to rename it to canoe.shtml.) If you want your files to retain .html or .htm extensions, ask your system administrator to configure the server to examine all files (not just files with a certain extension) for server-side includes. Parsing a file for server-side includes takes a little extra time, though, so pages that the server parses are served a little more slowly than other pages; some system administrators therefore won't provide the option of parsing all files.

To insert a server-side include:

1 Choose Insert > Server-Side Include or click the SSI button in the Common category of the Objects panel.
2 In the dialog box that appears, browse to and select a file.

To change which file is included:

1 Select the server-side include in the Document window.
2 Open the Property inspector.
3 Do one of the following:
Click the folder icon and browse to and select a new file to include.
In the text box, type the path and file name of the new file to include.