How to I use Server Side Includes (SSI) ?
Posted by Helpdesk Admin on 08 September 2009 10:35 AM
|
|
Server side includes are a simple mechanism whereby files containing web content can be included into other webpages by simply inserting a specially crafted comment called an SSI include that acts as a marker for the included file. At delivery time, the Apache web server scans for these SSI includes and replaces them with the contents of the included file. This allows designers a simple way to define commonly used website elements such as headers, footers and menus as a single file. Changing the included content file will immediately make the changes visible on all pages that include it saving much repetitive work when redesigning parts of your website. To use SSI, you must first ensure that it is enabled on your web hosting account (it usually is). To check this, log on to your control panel and navigate to Hosting -> Web Space -> WebSite Configuration and ensure that SSI Support is marked On, otherwise you should click Edit and enable this. The server will by default parse every page ending in .shtml for SSI Includes, but will not by default check normal .html pages as this would slow down delivery for all pages. To have the server parse specific .htm or .html pages, edit or create a file called .htaccess in the root directory of your website, and include the directive XBitHack On in this file. You can now designate which pages should be parsed for SSI includes by using the file manager or your FTP program to set execute permissions on selected pages (set file permissions to 755 or rwxr-xr-x). Basic SSI directivesSSI directives have the following syntax: <!--#element attribute=value attribute=value ... --> It is formatted like an HTML comment, so if you don't have SSI correctly enabled, the browser will ignore it, but it will still be visible in the HTML source. If you have SSI correctly configured, the directive will be replaced with its results. Example: Including another HTML file <!--#include virtual="header.html" --> This will include the contents of the file header.html into your web page at the location in the file where you place this comment. Example: Displaying Todays Date <!--#echo var="DATE_LOCAL" --> This will display the current date in your web page at the location in the file where you place this comment. For more information on SSI please check out the following links: | |
|