Home arrow HTML arrow Page 5 - Using SSI to Boost Efficiency

Using SSI to Boost Efficiency

Have you always thought Server Side Includes (SSI) was too complex? Check out Clay Dowling's tips as he explains some simple SSI directives and how to simplify managing navigation menus.

Author Info:
By: Clay Dowling
Rating: 4 stars4 stars4 stars4 stars4 stars / 9
August 16, 2004
  1. · Using SSI to Boost Efficiency
  2. · Enabling SSI
  3. · Simple SSI Directives
  4. · How to Use SSI
  5. · Navigation Menus
  6. · Common HTML Blocks
  7. · Business Considerations

print this article

Using SSI to Boost Efficiency - Navigation Menus
(Page 5 of 7 )

Every website has, or should have, navigation menus to make getting around the site easy. For the most part, these menus are the same on every page.  Even with a complex site, you'll have large numbers of pages with the same menus. That makes them a natural for managing with SSI.

A good example of a navigation menu from my site is below:

<span class="menuitem">
 <a href="/">Home</a>
<span class="menuitem">
 <a href="index.html">miniCMS</a>
<span class="menuitem">
 <a href="screenshots.html">Screen Shots</a>
<span class="menuitem">
 <a href="ptml.html">PTML</a>
<span class="menuitem">
 <a href="download.html">Download</a>

If I save this to the file "menu.shtml" I can now put the menu in all of my pages with the directive:

<!--#include virtual="menu.shtml" -->

The files included by a #include directive are also parsed for include directives. This means I can put a uniform page header on all my pages and make the menu part of that header. I'll put this bit of code in a file called "top.shtml":

<div class="banner">
<img src="images/miniCMS.jpeg" alt="miniCMS Logo">
<div class="menu">
<!--#include virtual="menu.shtml" -->

Through the magic of CSS we can also use our menu to make a nice navigation bar at the bottom of the page in "bottom.shtml":

<div class="footer">
<hr align="center">
<div class="menu">
<!--#include virtual="menu.shtml" -->
<p>&copy; 2004 by Megacorp Inc.</p>
<p><a href="mailto:webmaster@megacorp.net">Comments &amp; Questions</a></p>

Now when we add new pages to our website, the only place where we have to add a link to the page is in "menu.shtml". It will automatically appear in both the main menu at the top of the page and at the little bottom menu.

I have also successfully used a CGI program to generate my menus dynamically. Given how easy it is to maintain a single include file, I only recommend the CGI approach in situations where you're looking to generate a menu that changes based on context.  This could be good, for instance, where the menu shouldn't have an active link for the current page. In that case you'd use #exec instead of #include.

blog comments powered by Disqus

- Does HTML5 Need a Main Element?
- Revisiting the HTML5 vs. Native Debate
- HTML5: Not for Phone Apps?
- HTML5 or Native?
- Job Hunting? Freelancer.com Lists This Quart...
- HTML5 in the News
- Report: HTML5 Mobile Performance Lags
- The Top HTML5 Audio Players
- Top HTML5 Video Tutorials
- HTML5: Reasons to Learn and Use It
- More of the Top Tutorials for HTML5 Forms
- MobileAppWizard Releases HTML5 App Builder
- HTML5 Boilerplate: Working with jQuery and M...
- HTML5 Boilerplate Introduction
- New API Platform for HTML5

Watch our Tech Videos 
Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us 
Weekly Newsletter
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 

Developer Shed Affiliates


© 2003-2019 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials