Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Printer Friendly Page with SSI

SSI (Server Side Includes)

Printer Friendly Page with SSI

by  cian  Posted    (Edited  )
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:

[color blue]
Code:
 <a href="thispage.shtml?print">Print this page</a>
[/color]

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:

[color blue]
Code:
 <a href="<!--#echo var="DOCUMENT_URI" -->?print ">Print this page</a>
[/color]


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

[color blue]
Code:
<!--#if expr="$QUERY_STRING = 'print'" -->
<p>This is a printer friendly page.</p>
<!--#else -->
<p>This is the 'normal' content.</p>
<!--#endif-->
[/color]


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:

[color blue]
Code:
<html>
  <head>
   <title>Document title</title>
  </head>
 <body>
   <!--#if expr="$QUERY_STRING = 'print'" -->
   <p>This guide was printed from Tek-tips.com.</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 Tek-tips.com</p>
   <!--#else -->
   <!--#include virtual="/includes/document-footer.inc" -->
   <!--#endif-->
 </body>
</html>
[/color]


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

[color blue]
Code:
 <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>
[/color]


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:
[color blue]
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!
<!--#endif-->
[/color]


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:
http://www.ssi-developer.net/
http://www.ssi-developer.net/?print



Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search

Back
Top