DreamweaverFAQ.com
Search the site!Search DWfaq.com | Print This PagePrinter Friendly Page
Current: Default | Default: Snazz-o-Matic


DreamweaverFAQ.com » Tutorials » Dynamic » Using Server Side Includes


How to use Server Side Includes (SSI)

What's a Server Side Include?

As sites become larger and larger, site management becomes a larger worry. How do I keep a 2000 page site updated? How do I keep navigation elements consistent? How do I manage to change the nav on a 2000 page site without losing all my hair? There a few methods in Dreamweaver to accomplish this:

  1. Templates
  2. Library Items
  3. Server Side Includes

Templates and Library Items can be used with any type of server, and SSI can as well, provided your host has enabled the ability. In order to use SSIs, your page must have an extension that will be processed by the server, .html usually won't do the trick. If you're on a UNIX box, it will need to be .shtml or if you're using some other server language (regardless of server type), it would need to be .php, .cfm, .jsp, .asp or .aspx or any other server language you may be using. The syntax for calling the SSI will depend on which server language you're using. We're going to be using the ASP VBScript syntax since that's what I do my development with. If you're using another server language, here's the necessary syntax:

ASP and .NET:

<!-- #include file="include.asp" -->

ColdFusion:

<cfinclude template="include.cfm">

PHP

<?php require_once('include.php'); ?>

JSP

<%@include file="include.jsp" %>

Notice that I've added the appropriate server language extension to the includes. This ensures that the include would be processed by the server if a user somehow found out the include name and put it directly into their browser. If you're putting server side code in your includes, you should make sure they're always processed by the server.

Pros and Cons

There are a few advantages/disadvantages to each of these three methods. I personally prefer includes simply for their ease of use and the ability to quickly update an entire site by changing just one file.

Templates
Pros:

  • No server side action needed
  • Can be applied to every page in a site
  • With new MX templates, you can include optional and repeating regions as well as nested templates

Cons:

  • Changes are physically made to every page based on a template.
  • Updating one item requires every page to be updated and uploaded (a huge hassle on a large site).
  • Templates are Dreamweaver specific. If you edit the page in an external editor you run the risk of destroying the template markup.

Library Items
Pros:

  • No server side action needed
  • Can be applied to every page in a site
  • Can be applied to any part of page

Cons:

  • Changes are physically made to every page based on a template.
  • Updating one item requires every page to be updated and uploaded (a huge hassle on a large site).
  • Libraries are Dreamweaver specific. If you edit the page in an external editor you run the risk of destroying the library markup.

Server Side Includes
Pros:

  • Change one file and every file that uses that Include is instantly updated
  • Every server language supports them in one form or another
  • Easier to reuse code pieces

Cons:

  • Server has to parse each page that uses includes

How do they work?

Server Side Includes are just that, a way for the server to include one file inside another before the page is sent to the browser. This allows you to include page elements in an external file and have them inserted into the page called by the user. Here's a very simple example using three files. The content.asp page is what the user is viewing. It calls two includes (inc_top.asp and inc_bottom.asp) in order to wrap the content in a table.

content.asp:

<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<html> <head>
<title>My Content Page</title>
</head> <body>
<!-- #include file="inc_top.asp" -->
My content goes here.
<!-- #include file="inc_bottom.asp" -->
</body>
</html>

inc_top.asp:

<table><tr><td>

inc_bottom.asp:

</td></tr></table>

When the viewer pulls up http://www.yourdomain.com/content.asp in their browser, the server parses content.asp and includes our two include files and sends the resulting page to the browser. If the user views the source code of content.asp, they'll see this:

<html>
<head>
<title>My Content Page</title>
</head>
<body>
<table><tr><td>
My content goes here.
</td></tr></table>
</body>
</html>

The server has replaced the two include calls with the content of those files, just as it would any other server side code (notice the LANGUAGE attribute isn't there either). Let's take this a little further in the next section.

::back to top::

::This page last modified 8/13/2013 at 03:37::

Copyright © 2001-2024 DreamweaverFAQ.com All Rights Reserved.
All brands, trademarks, tutorials, extensions, code, and articles are the property of their respective owners.
A production of Site Drive Inc.
Legal Notice | Privacy Policy | Disclaimer & Notice