How To Incorporate "Include" Files Into 20/20 DataShed's Pages
To SSI or Not To SSI?
We recommend that you do not use the traditional SSI syntax with 20/20 DataShed but instead use the Server.Execute() method. The traditional #include syntax looks like this:
<!--#include file="a-file.asp"-->
or <!--#include virtual="a-file.asp"-->
We recommend that you avoid the #include directives demonstrated above.
"Why?" you might ask.
Because this type of #include command is processed before the page is executed and that prevents (or limits) 20/20 DataShed's ability to execute your "included" ASP code conditionally. While the Server.Execute() method allows the opportunity to call extraneous code after the ASP page processing has started -- this is ideal within 20/20 DataShed's framework.
Because this type of #include command almost certainly requires that you make modifications to 20/20 DataShed's ASP source files. This is not ideal as it prevents you the ability to smoothly upgrade if/when we release updates to the product.
The Server.Execute() method offers other benefits too:
The Server.Execute() method calls external ASP scripts -- not just snippets of code but fully-formed ASP documents. Those same scripts can be called by any other ASP file in your web site; so you can re-use the code in a very modular fashion throughout your web site if you choose.
The Server.Execute() method can be invoked anywhere, anytime (or not!) from within an ASP document. If the external script is not necessary for every rendition of the page, then the server doesn't have to expend energy to parse and process the code. Traditional #include files, on the other hand, are always executed and parsed by the server even if the code isn't necessary in every rendition of the page.
...and the best part is...
20/20 DataShed contains a hook in its skinning engine which will execute your own code whenever, wherever you want! You merely have to:
Create the ASP script that you want to execute,
then put a little token in your template.html file to tell 20/20 DataShed where you want the content to appear on your pages.
Do We Practice What We Preach?
Yes, and no. We use both methods. Obviously, traditional SSI syntax is still very powerful and indeed 20/20 DataShed uses the #include directives generously throughout the product.
However we feel that the Server.Execute() method is the best available option for those who want to author their own scripts, plug-ins, extensions, etc. to extend 20/20 DataShed's features. For instance, when we develop plug-ins or add-ons for 20/20 DataShed, we have quite a strict policy that the core product should not be altered in any way to accomodate the additional feature(s) -- and to accomplish that goal we have found the Server.Execute() method to be extremely useful. That experience leads us to this conclusion: you should use the Server.Execute() method instead of the #include directive.
Well, More Rock and Less Talk, eh? Let's Get Started...
Tutorial #1: A Copyright Notice for Your Web Site
Let's create a simple script which will write a single line of HTML to the pages of your web site: Like this:
To demonstrate how easy this is, we'll begin with this very simple (but also quite practical) script.
In this tutorial, we will perform the following actions:
Create a new .asp page that 20/20 DataShed (or any other ASP page/product) can execute. The new script will output a simple copyright message.
Explanation of the code in this basic example.
Edit the template.html to instruct 20/20 DataShed when/where to execute the new ASP script.
And last, if you have other ASP pages in use on your web site then we'll show you how to execute this new script from those other pages.
Step 1: Create a new .asp page that 20/20 DataShed (or any other ASP page/product) can execute. The new script will output a simple copyright message.
Open a text editor such as NotePad. You may also use an HTML editor and select the option to edit the "HTML source" directly.
Save the new document as "myCopyright.asp" to your hard drive. (You may wish to save it to a specific folder if you keep a local copy of your web site on your own computer.) Note, if you save the file using Notepad, then Microsoft Windows might append the .TXT extension to your file. Please ensure that the file is called "myCopyright.asp" and not "myCopyright.asp.txt" -- to do this you might need to alter the "Folder Options" in Windows Explorer so that the file extensions are not hidden.
With NotePad still open, copy-n-paste the following code into the new document. Alter the blue text as necessary.
Upload it to your web site. (Please...if you already have a file named "myCopyright.asp" then give this file a different name before uploading it to your web site.)
The script is now complete but should be tested. Open your web browser and visit this new page by typing the URL into your web browser's address bar. You should see a simple copyright notice (and nothing else) like our example above. If you see an error message, then please restart this tutorial and pay close attention to the instructions.
If the script does not produce an error message, then move on to the next section: Step 2.
Step 2: Explanation of the code in this basic example.
This line contains the language declaration (Language="VBScript") and identifies the file as an ASP document (<% %>).
This line also instructs the web server to disable "sessions": (ENABLESESSIONSTATE="False"). This instruction is optional. We have chosen to disable sessions throughout 20/20 DataShed because doing so saves a considerable amount of overhead on the web server and DataShed doesn't require sessions for any internal features.
If your purposes require sessions, then you could rewrite this line as follows: <%@ Language="VBScript" %>
Option Explicit
response.buffer = true
We have used the option explicit declaration throughout 20/20 DataShed. We recommend that you use this option in your own scripting as well.
The response.buffer is set to "true" throughout 20/20 DataShed. Unless you have good reason to alter this property, then we suggest you leave this line as it is.
Note that you might be tempted to write additional headers to the file, such as the following:
response.expiresAbsolute
response.CacheControl
We recommend that you do not use these headers in an .asp document such as this (i.e. one that will be executed using the Server.Execute() method) unless you know exactly what you're doing and have good reason for including these options. In our experience, we have found that these properties of the "Response" object can cause runtime errors if they conflict with the processing of the "calling" page (i.e. the page/script which is executing this external code.)
CONST strCompanyName = "Your Company Name Here"
CONST yearEstablished = 2005
These two lines should be edited to reflect your own company name, and the year in which your company was established.
These constants are used later in the scripts.
dim yearNow
yearNow = Year(Now())
The yearNow variable in this code will store the current four-digit year.
dim strDuration
IF yearEstablished <> yearNow THEN
strDuration = yearEstablished &" - "& yearNow
ELSE
strDuration = yearNow
END IF
The strDuration variable in this code will store some text.
The IF THEN statement is used to perform some simple logic and will produce text for the strDuration variable. That logic, in simple English, looks like this:
If (the company was not established this year) then
let's display text that looks like this: FROMYEAR - PRESENTYEAR (i.e. "1984 -
")
otherwise
let's just display the current/present year (i.e. "
")
Finally, we can print the text and some additional HTML to the page.
Step 3: Edit the template.html to instruct 20/20 DataShed when/where to execute the new ASP script.
In the previous sections we created an ASP file -- a "stand-alone" script with a very simple purpose to produce a copyright notice. Now we will show you how 20/20 DataShed's skinning engine can execute ("include") that file within your template.
Access your web site with an FTP application such as CuteFTP, FTP Explorer, or Windows "My Network Places".
Download template.html from the templates folder of this application to your local computer.
Open the file in a text editor such as Notepad or a WYSIWYG editor. (If you choose to use an editor, then please ensure that you select the option to edit the "source" directly.)
In that file, find the area in which you want to "include" the copyright notice.
Place the following token in your template where you want the copyright notice to appear:
[2020Execute_myCopyright.asp]
In the example code below, you can see that we'll include the copyright notice in the "footer" of the file and we've placed it into a <div> that will center-align the content.
<html>
<head>
<title></title>
</head>
<body>
<!-- HEADER STUFF -->
<h1>Welcome!</h1>
<!-- END OF HEADER STUFF -->
<!-- BODY (Main Content) STUFF -->
... content...
... content...
... content...
<!-- END OF BODY STUFF -->
<!-- FOOTER STUFF --> <div style="text-align:center;">[2020Execute_myCopyright.asp]</div>
<!-- END OF FOOTER STUFF -->
</body>
</html>
Save the file.
Upload the file to your web site using the FTP application and overwrite the existing "template.html" file.
Reload the listings.asp, newuser.asp, or login.asp page and include the "?objApplication=RemoveAll" querystring in your URL to force 20/20 DataShed to flush out the old template from the server's cache (and reload this new one).
You should see your new copyright notice within your template.
Step 4: How to execute this new script within your other ASP pages.
The new file we've created together, "myCopyright.asp", can be executed by any ASP script on your web site. In this manner, you can create content for your web site in a very modular fashion and reproduce that content in 20/20 DataShed's pages and your own. Imagine the possibilities: news flashes, banners, advertisements, headers, menus, scripts...all shared by your own .asp files and ours!)
By placing the following line into your own ASP scripts, you can execute the "myCopyright.asp" file and include its output into your own documents.
<% Server.Execute("myCopyright.asp") %>
If the line above works properly, then great...if it doesn't then here are a few hints to get it working properly in your scripts:
The script delimiters (<% %>) might not be necessary if you've placed this line within an existing script block. Perhaps try removing the script delimiters.
Example: <% Server.Execute("myCopyright.asp") %>
You may need to determine where the file, "myCopyright.asp", is located in relation to your own script. In our examples above, we have assumed that you own ASP document is in the same folder as the "myCopyright.asp" file. If it isn't, then you can address the external file by its path relative to the application's root folder.
If "myCopyright.asp" is in the same folder as the "calling" page:
Server.Execute("myCopyright.asp")
If "myCopyright.asp" is in the web site's root folder:
Server.Execute("/myCopyright.asp")
If "myCopyright.asp" is in a folder called "foo" under the web site's root folder:
Other examples of this technique can be seen in the related topics below. If you would like to see a tutorial about a specific topic, please let us know.