Home     SSI Lab     CSS Templates     CSS     Htaccess     Web Design     XHTML

X-SSI Lab

graphic-img   

SSI-D HOME

SSI LAB

Introductory Topics

SSI Directives

Extending SSI

Apps/Examples

Top Resources

CSS Templates

CSS

.Htaccess

Web Design

(X)HTML

HTML-Kit

Resources





Printer Friendly Page with SSI

Introduction

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>
<!--#endif -->

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 and footer leaving only the content on the printer friendly page:

<html>
  <head>
   <title>Printer Friendly Document</title>
  </head>
 <body>
   <!--#if expr="$QUERY_STRING = 'print'" -->
   <p>This guide was printed from SSI-Developer.net.</p>
   <!--#else -->
   <!--#include virtual="/includes/document-header.inc" -->
   <!--#endif -->

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

   <!--#if expr="$QUERY_STRING = 'print'" -->
   <p>For more guides visit SSI-Developer.net</p>
   <!--#else -->
   <!--#include virtual="/includes/document-footer.inc" -->
   <!--#endif -->
 </body>
</html>

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):

<html>
<head>
<title></title>
<!--#include virtual="/includes/scripts.txt" -->
</head>
<body>
<!--#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" -->
</body>
</html>

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.

header.shtml:

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

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




Advertisement Sign up for free to PayBox.me today and get $25 just for joining AND earn up to $20 per day for participating.