Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

SSI (Server Side Includes)

Printer Friendly Page with SSI by cian
Posted: 9 Jun 03

This guide shows you one method to create a printer friendly version of your pages using SSI. I recommend that you have a page template set up using SSI but this method also works if you don't.

This method makes use of the query string. By passing a certain value in the page URL the browser can read the query string when parsed and display the required content based on that value.

To pass our value into the query string we can set up a link such as:

 <a href="thispage.shtml?print">Print this page</a>

That link works for the document thispage.shtml so to set it up so that we can copy the same code into multiple pages we can do the following:

 <a href="<!--#echo var="DOCUMENT_URI" -->?print ">Print this page</a>

We then use the SSI flow control elements to read our keyword "print" to display or 'remove' the content:

<!--#if expr="$QUERY_STRING = 'print'" -->
<p>This is a printer friendly page.</p>
<!--#else -->
<p>This is the 'normal' content.</p>

You can insert the above code into many areas of your document to display specific content. If we take a basic HTML document with header footer and content section we may decide to remove the header amd footer leaving only the content on the printer friendly page:

   <title>Document title</title>
   <!--#if expr="$QUERY_STRING = 'print'" -->
   <p>This guide was printed from Tek-tips.com.</p>
   <!--#else -->
   <!--#include virtual="/includes/document-header.inc" -->

   <p>Here is my printer friendly content !!</p>

   <!--#if expr="$QUERY_STRING = 'print'" -->
   <p>For more guides visit Tek-tips.com</p>
   <!--#else -->
   <!--#include virtual="/includes/document-footer.inc" -->

If you already have your site built it can be a difficult task entering this code into every document. To get around this you can enter the code into the included files IF you are using includes to set up your page template, and IF the included files are set up to be parsed by the server.

To explain this further I will use my own site template as an example. The basic template I use for every page on this site is as follows (excluding Meta tags and DTD):

<!--#include virtual="/includes/scripts.txt" -->
<!--#include virtual="/includes/header.shtml" -->
<!--#include virtual="/includes/left_col.shtml" -->

<!-- enter content here -->

<!--#include virtual="/includes/right_col.shtml" -->
<!--#include virtual="/includes/footer.shtml" -->

So when I decided to create a printer friendly version of my webguides I simply had to edit four include files; header.shtml, left_col.shtml, right_col.shtml and footer.shtml to enter the printer code.


<!--#if expr="$QUERY_STRING = 'print'" -->
<p>This guide was printed from SSI-Developer.net.</p>
<!--#else -->
Logo, links and top navigation bar go here!

Editing those four include files and entering the printer code now allows me to remove the header, footer, left and right colums thus leaving only the content. Hey Presto, a printer friendly version of every (.shtml) page of the site.

To test this method compare the following pages:

Back to Linux (server) FAQ Index
Back to Linux (server) Forum

My Archive

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close