Create Easy site-wide
changes with Server Side Includes
When you develop big web sites with parts of the web pages
having repetitive content, you must use Server Side Includes(SSI).
You can notice in this site itself all the sections have the
same header, menu. If need to make any change in these areas
have to manually change it in all pages or if using templates
or libraries have to FTP all the pages whenever we make a
change. If we use Includes we can make the change only in
the Include and it automatically gets upgraded in all the
sites which uses that Include.It really reduces a lot of our
FTP time as we only need to FTP one file. (If you are familiar
with templates and libraries you will know that it reduces
your development time a lot. Still have to FTP all the files
that use the library or template. When using SSI's are different).
What are Server Side Includes?
It allows you to write some commonly used code once and have
the server insert it into the pages for you. An include file
has code that you want to reuse. Any ASP or SHTML page that
wants to use the code in the include file will have a special
line that indicates the place holder for the code.
This code will be like: <!--#include virtual="/path"
-->
This results in the server taking the entire content of the file and inserts it into the page, replacing the <! -- #include ..--> line.
How to use Server Side Includes
It is very easy to use. Create a .htm, .html or .asp file
which have the reusable code. for an example take the header
in this site. The header is an html file (Important: This
should not contain any HTML, HEAD or BODY tags). So the code
will start and end with the TABLE tag.
Very Important: If you are using highly confidential ASP
code (or any other web technology), like your database connection
string or some business logic, in your include file then make
sure the include file is named .asp so that nobody can open
and see your code.
Once made the Include file, include it in all the pages that
uses this code. Go to the page which will use this include
and add the following code in the appropriate place:
<!--#include virtual="/path" --> Replace path with the path of the Include file.
Anytime you wish to make a change in the Include it will
robotically get updated in every pages using the Include and
you can change only FTP one page instead of changing hundreds
of pages.
Important points while using Server Side Includes
- All the pages using Server Side Includes
should be .asp or .shtml files.
- The Include itself must not have any <
HTML>, <HEAD> or <BODY> tags. The file contain
the code that has to be included into a file.
- If you using ASP code in include file then
make sure the include file is named .asp so that nobodycan
open include file and see your code.
- All paths used in the code of an Include file (i.e. images, links, etc.) must be relative to Site root and not relative to document.
- While you use an Include within a file it
must be included relative to Site Root and not relative
to Document.
Using Server Side Includes in Dreamweaver
Once you have made your Include file then Click on Insert
> Server Side Includes, select the file you need, make
sure the path is relative to Site Root and insert it.
Hope this time saving tip useful. If you aren't familiar
with Templates then you can read our article on Using Templates
in Dreamweaver.
|