iEntry 10th Anniversary Webforumz RegistrationAnnouncements Contact Webforumz StaffContact
Home Resources Blogs Meet the Team Contact Register
 

Go Back   WebForumz.com > The Code > Classic ASP

Closed Thread
 
LinkBack Thread Tools
Old August 13th, 2003, 04:45 AM   #1
New Member
 

Join Date: Jul 2003
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Altering Power: 0 administrator is on a distinguished road
ASP Include Files (SSI or Server Side Includes)

ASP Include Files (SSI or Server Side Includes)

People often have identical sections of code spread throughout many ASP pages, typically code at the top of the page (usually referred to as the header) and the lower part of the page (the footer).

Similarly, you may have code that performs a certain set of instructions that you are repeating across multiple pages. Consider this really basic example:-
Code:
<textarea cols=40 rows=6><%
If foobar="yes" then
response.write "YES!"
Else
response.write "NOT YES!"
End if%></textarea>
Ok, ok... it’s simple, but imagine that you used this on multiple pages. What’s wrong with this picture??

Well... you don’t have to think about that long before realising that if you ever wanted to change something about that piece of code, you’d have your work cut out… you would have to change every page... everyone has done this at some stage and luckily most usually take the steps to learn a way around this problem.

If we could save our valuable chunk of code into a file and have that file accessed whenever we needed the code, then we no longer have a problem when it comes to changing things, as we simply update one file. Include files or Server Side Includes (SSI) as they are more commonly known are a powerful way to not only save time when it comes to maintaining and updating a site, but also increase efficiency and speed of that site too!

Ok, lets see how we use an include file... to start with we need to use one of two methods. The first one allows for including files relatively. By that I mean relative to the directory the ASP file that is using the include file resides. The second method includes files virtually. Including files virtually means that the path is taken from the root directory.

Consider that we are going to have a file (/main/somefile.asp) include another file (/includes/someinclude.asp).

To demonstrate, relative inclusion, look at this:-
Code:
<textarea rows=7 cols=50><% 
Response.Write "executing included code now"
%>

<% 
Response.write "done executing included code"
%></textarea>
And here, we give an example of the other method, virtual inclusion:-
Code:
<textarea rows=7 cols=51><% 
Response.Write "executing included code now"
%>

<% 
Response.write "done executing included code"
%></textarea>
Note the slight difference between the two methods. With virtual inclusion, you can move the file that calls upon the include file anywhere without affecting the outcome, because the path is always relative to the root. The same cannot be said however for relative inclusion. If you move a file that is using relative inclusion to a different directory, you’ll most likely find the relative path is no longer correct.

From the examples above, you may also notice that both methods, when calling the include do so OUTSIDE of the ASP script block. This because #include declarations are not interpreted by ASP. Include files are included before a single line of ASP is processed which means the following WONT work:-
Code:
<textarea rows=5 cols=50><%
Page=request.form("page")
%>

</textarea>
We were attempting to perform a dynamic include and I would be the first to admit that the above would be very useful indeed if in fact it were possible. I do intend to cover a few methods that work around this set back at a later date.

I hope that you have found the above informative and hope it inspires you all to write code that’s more efficient and more easily maintained.
administrator is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Old August 13th, 2003, 12:04 PM   #2
Anonymous User
Guest
 

Posts: n/a
Very well said, thank you for the great info...
 
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Old August 15th, 2003, 10:47 AM   #3
New Member
 

Join Date: Aug 2003
Location: USA
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Altering Power: 0 CTifer is on a distinguished road
<blockquote id="quote"><font size="1" face="geneva, verdana, arial" id="quote">quote:<hr height="1" noshade id="quote"><%
Response.Write "executing included code now"
%>

<%
Response.write "done executing included code"
%><hr height="1" noshade id="quote"></blockquote id="quote"></font id="quote">

Just so you're aware, did you know that the include will actually be done BEFORE that Response.Write is executed. It doesn't come across the response.write, write it, then include the file.

Includes are ALWAYS processed first.
CTifer is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Old August 15th, 2003, 10:51 AM   #4
Rob
Elite Veteran
SuperMember
 
Rob's Avatar
 

Join Date: Jul 2003
Location: Southern UK
Age: 35
Posts: 3,133
Blog Entries: 7
Thanks: 28
Thanked 22 Times in 19 Posts
Rep Altering Power: 0 Rob is a jewel in the rough Rob is a jewel in the rough Rob is a jewel in the rough
Hi ....

Yes I know that...

as I said up above somewhere...

<blockquote id="quote"><font size="1" face="geneva, verdana, arial" id="quote">quote:<hr height="1" noshade id="quote">Include files are included before a single line of ASP is processed<hr height="1" noshade id="quote"></blockquote id="quote"></font id="quote">

Maybe I used a bad example.
__________________
Rob - Webforumz Founder

Latest Project: Sanctuary for Student Midwives
Rob is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Closed Thread

Bookmarks

Tags
asp , include , files , ssi , server , side , includes


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Java server side technologies asim The Café 0 June 20th, 2007 04:47 AM
Trouble with Server Side Includes BGarner Classic ASP 3 January 20th, 2007 02:16 PM
Server side executables Donny Bahama PHP 4 December 30th, 2006 02:59 PM
Client-Side VS Server Side Scripting redev2006 JavaScript 1 July 30th, 2005 04:30 PM
do server side includes affect performance? spinal007 Classic ASP 13 May 5th, 2004 09:34 AM


Search Engine Optimization by vBSEO 3.2.0 RC8