CGI: VBScript Banner Footer: Difference between revisions

Punctuation and grammatical changes; some clarification.
(Created page with "{{Nav CGI}} '''VBScript Banner and Footer''' Generally web pages consist of three parts a banner, page content and footer. This page covers a very basic page template and a fu...")
 
(Punctuation and grammatical changes; some clarification.)
 
Line 3: Line 3:
'''VBScript Banner and Footer'''
'''VBScript Banner and Footer'''


Generally web pages consist of three parts a banner, page content and footer.
Generally web pages consist of three parts: a banner, page content and a footer.


This page covers a very basic page template and a function to simulate PHP’s file include .
This page covers a very basic page template and a function to simulate PHP’s file include.


__TOC__
__TOC__
Line 14: Line 14:
|
|
===Basic page template===
===Basic page template===
Basic page template is shown on right.
A sbsic page template is shown on right.


* Every page starts with a shebang line followed by a Content-type line.
* Every page starts with a shebang line followed by a Content-type line.
* Next three lines are the minimum tags required for an html page. You can add tags such as meta, link and script as required for your application.
* The next three lines are the minimum tags required for an html page. You can add tags such as meta, link and script as required for your application.
* The page body is split into three sections '''banner''', '''content''' and '''footer'''
* The page body is split into three sections: '''banner''', '''content''' and '''footer'''
* Last three lines are html closing tags and an optional script return code.
* The last three lines are html closing tags and an optional script return code.


'''Note:''' Replace HTML single parameters quotes with double quotes for example style="color:red" becomes style=""color:red""
'''Note:''' Replace HTML single parameters quotes with double quotes; for example, style="color:red" becomes style=""color:red""


* Create a new file test4.vbs with content as shown on right.
* Create a new file test4.vbs with content as shown on right.
Line 53: Line 53:
|
|
The script produces output as shown on right.
The script produces output as shown on right.
Admittedly nothing spectacular a real page banner may include
Admittedly it's nothing spectacular. A real page banner may  
such items as images, text or even news announcements.
include such items as images, text or even news announcements.
Similarly the footer can be as complex as you like.
Similarly, the footer can be as complex as you like.


Generally the same banner and footer are used on every page
Generally the same banner and footer are used on every page,
providing your site with a consistent look.
providing your site with a consistent look.


Line 72: Line 72:
|}
|}


'''''[[#top | Top]]'''''
 
==File Includes==
==File Includes==
Changing either the banner or footer requires editing each page in your site. This is time consuming and prone to errors. Ideal solution is to save the banner and footer code in external files and includes these with an appropriate include statement.
Changing either the banner or footer requires editing each page in your site. This is time consuming and prone to errors. The ideal solution is to save the banner and footer code in external files and include these with appropriate include statements.


The following may come, as a surprise unlike PHP there is no way in either VBScript or JavaScript to directly include an external file.
The following may come as a surprise: unlike PHP, there is no way in either VBScript or JavaScript to directly include an external file.


{|
{|
Line 85: Line 85:




'''Note:''' You can pass either an absolute path or just a file name to the function. Specifying only a file name requires that file, to exist in the folder where the working script resides.  
'''Note:''' You can pass either an absolute path or just a file name to the function. Specifying only a file name requires that file to exist in the folder where the working script resides.  
|
|
<pre>
<pre>
Line 103: Line 103:
</pre>
</pre>
|}
|}
'''''[[#top | Top]]'''''
 
==Test Script 5==
==Test Script 5==
In test folder UniServer\www\vbs_test create three new files as shown blow:
In test folder UniServer\www\vbs_test, create three new files as shown below:


{|
{|
Line 129: Line 129:
|
|
===Test script===
===Test script===
The test page includes the above function and original banner and footer text have been replaced with calls to this function.
The test page includes the above function, and the original banner and footer text have been replaced with calls to this function.
These calls pull in the appropriate files and run the code they contain.


These calls pull in the appropriate files and run the code they contain.
===Run test script===
===Run test script===
* Start Apache if not already running
* Start Apache if not already running
* Enter: <nowiki>http://localhost:8081/vbs_test/test5.vbs</nowiki>
* Enter: <nowiki>http://localhost:8081/vbs_test/test5.vbs</nowiki>
* Result shown below
* Result is shown below
===Result===
===Result===
Result shown below:
Result shown below:
Line 148: Line 148:
<span style="font-weight:bold;font-size:16px;color:green">Footer CGI Test 5</span>
<span style="font-weight:bold;font-size:16px;color:green">Footer CGI Test 5</span>
</div>
</div>
A slight disadvantage with this solution the simulated include file function must be included on every page of your site. That said it is a relatively small amount of code resulting in a positive advantage of having the ability to include files.
A slight disadvantage with this solution is that the simulated include file function must be included on every page of your site. That said, it is a relatively small amount of code, resulting in a positive advantage of having the ability to include files.


'''Note:''' Included files are not restricted to the file extension .vbs any other suitable extension can be used for example .inc or.txt  
'''Note:''' Included files are not restricted to the file extension .vbs . Any other suitable extension can be used, such as .inc or .txt .


|
|
Line 192: Line 192:
|}
|}


'''''[[#top | Top]]'''''
== Summary ==
== Summary ==
The include file function is not limited to loading a banner or footer file it also allows you to have a separate file containing a set of common functions for your site.
The include file function is not limited to loading a banner or footer file. It also allows you to have a separate file containing a set of common functions for your site.


Although the above include file function can be used there is a better alternative, this is covered in the [[CGI: JavaScript CGI|JavaScript]] section.
Although the above include file function can be used, there is a better alternative. This is covered in the [[CGI: JavaScript CGI|JavaScript]] section.


'''''[[#top | Top]]'''''
==Where to next==
==Where to next==
An import reason for using CGI scripts is to process data sent with a page request. For example this can be data entered in a form this data sent is in a special format referred to as URL encoding. [[CGI: URL Encoding|Next page]] covers URL Encoding.
An import reason for using CGI scripts is to process data sent with a page request. For example, this can be data entered in a form. The data sent is in a special format, referred to as URL encoding. The [[CGI: URL Encoding|next page]] covers URL Encoding.


'''''[[#top | Top]]'''''
----
----