Forums >> Programming >> Proof of Concept (POC) >>
Server Side Includes (SSI)




Posted:
bvstone

Server Side Includes (SSI)

 
Server Side Includes (SSI)

The Field Exit site extensively uses Server Side Includes (SSIs) to display static and dynamic content.  From the headers, to the footers, to displaying groups, forums and topics we really try to use SSI wherever we can.

The first example you'll see is that every page has (or should have!) a footer with copyright information.  This is done by using a static SSI at the bottom of each page, like so:

<!--#include virtual="/ssi/bottom.html" -->

This SSI statement is interpreted by the HTTP Web Server.  The contents of "/ssi/bottom.html" are then included in place of this SSI statement.

The contents of the /ssi/bottom.html file are as follows:

<!--begin bottom-->
    <br />
    <hr />
    <table width="100%">
      <tr>
        <td class="small1" nowrap="nowrap"> Copyright 1983-2014 BVSTools
        <br />GreenBoard(v2) Powered by the 
        <a href="http://www.erpgsdk.com" target="_blank">eRPG SDK</a>, 
        <a href="http://bvstools.com/mailtool.html" target="_blank">MAILTOOL Plus!</a>, 
        <a href="http://jquery.com" target="_blank">jQuery</a>, 
        <a href="http://jqueryui.com/" target="_blank">jQuery UI</a>, 
        <a href="http://ckeditor.com/" target="_blank">CKEditor</a>
        <br /></td>
      </tr>
    </table>
 <!--end bottom-->

Another way we use SSI is for the header, title and meta tags used by crawlers to index sites.  Because we want each page to be different, we used a CGI (in this case eRPG) program so the information generated can be dynamic.

First, we set up a physical file as such:

File Name . . . . PAGEPF                                   
  Library . . . .   GREENBOARD                             
Format Descr  . .                                          
Format Name . . . RPAGE      
File Type . . . . PF            Unique Keys - N 
                                                           
Field Name FMT Start Lngth Dec Key Field Description       
PAGEPATH    A      1   128         Page Path               
TITLE       A    129  1024         Page Title              
METADESC    A   1153  1024         Meta Description        

Next, we added a SSI directive to each of our pages.

<!--#include virtual="/forum/top?path=/index.html" -->

As you can see, instead of a static file, this SSI directive is calling an CGI program and passing in the page name (in this case, /index.html).

There is one CGI program that is a little different, and that's the one that displays the message.  The SSI directive for this program (DISPLAY) looks like this:

<!--#include virtual="/forum/top?path=/forum/display&subject=/%subject%/" -->

Obviously we are replacing the /%subject%/ string with the actual subject of the message.

Our CGI program will read the value of the path and subject variables.  If the subject is blank, then go to the PAGEPF file and try to find the Title and Meta Description for that path.  If a path isn't found out program will output a preset text for the text and description.  If there is a subject passed in, then use that for the title and meta description.

Here is a snippet from the template used by the CGI program "top"

<html>
	<head>
		<title>/%title%/</title>
		<meta name="description" content="/%metadesc%/">

...

Now, in our CGI program we simply replace these values with the values from the PAGEPF file (or the subject, if it's passed in):

#startup();                                   
inPagePath = #getData('path':1:LOWER); 
inSubject = #getData('subject');   

#writeTemplate('stdhtmlheader.erpg');         
#loadTemplate('top.erpg');                    

if (inSubject <> ' ');                                                 
  #replaceData('/%title%/':%trim(inSubject) + ' - FieldExit.com');    
  #replaceData('/%metadesc%/':%trim(inSubject) + ' - FieldExit.com'); 
else;                                                                  
  exec SQL                                                           
    select 1, TITLE, METADESC                                        
    into :i, :TITLE, :METADESC                                       
    from PAGEPF                                                      
    where PAGEPATH = :inPagePath;                                    
                                                                   
  if (i = 1);                                                        
    #replaceData('/%title%/':TITLE);                                 
    #replaceData('/%metadesc%/':METADESC);                           
  else;                                                              
    #replaceData('/%title%/':                                        
                 'Field Exit - IBM i (System i, iSeries, AS400) ' +  
                 'Blog, Forum and Community');                       
    #replaceData('/%metadesc%/':                                     
                 'Field Exit - IBM i (System i, iSeries, AS400) ' +  
                 'Blog, Forum and Community');                       
  endif;

endif;                                                             

#writeSection();    
#cleanup();         
                    
*INLR = *on;        

Pretty simple program, especially with the help of the eRPG SDK.  Using a product like CGIDEV2 would be just as easy.

There are many other uses of SSI in this web application.  We will hopefully cover those in more detail in the future.

Brad


Last edited 09/08/2014 at 11:31:22


Reply




Copyright 1983-2017 BVSTools
GreenBoard(v3) Powered by the eRPG SDK, MAILTOOL Plus!, GreenTools for Google Apps, jQuery, jQuery UI, BlockUI, CKEditor and running on the IBM i (AKA AS/400, iSeries, System i).