ASP Include Files (SSI or Server Side Includes)

This is a discussion on "ASP Include Files (SSI or Server Side Includes)" within the Classic ASP section. This forum, and the thread "ASP Include Files (SSI or Server Side Includes) are both part of the Program Your Website category.



 Subscribe in a reader

Go Back   Webforumz.com > Main Forums > Program Your Website > Classic ASP

Notices


Closed Thread
 
LinkBack Thread Tools
  #1  
Old Aug 13th, 2003, 07:45
New Member
Join Date: Jul 2003
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
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: Select all
<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: Select all
<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: Select all
<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: Select all
<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.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!

  #2  
Old Aug 13th, 2003, 15:04
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!
  #3  
Old Aug 15th, 2003, 13:47
New Member
Join Date: Aug 2003
Location: USA
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
<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.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
  #4  
Old Aug 15th, 2003, 13:51
Rob's Avatar
Rob Rob is offline
Webforumz Founder
Join Date: Jul 2003
Location: Southern UK
Age: 34
Posts: 3,160
Blog Entries: 7
Thanks: 27
Thanked 19 Times in 16 Posts
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.
__________________
Click the 'Thanks!' button if this post has helped you

Rob - Webforumz Founder
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Closed Thread

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

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 Webforumz Cafe 0 Jun 20th, 2007 07:47
Trouble with Server Side Includes BGarner Classic ASP 3 Jan 20th, 2007 17:16
Server side executables Donny Bahama PHP Forum 4 Dec 30th, 2006 17:59
Client-Side VS Server Side Scripting redev2006 JavaScript Forum 1 Jul 30th, 2005 19:30
do server side includes affect performance? spinal007 Classic ASP 13 May 5th, 2004 12:34


All times are GMT. The time now is 22:19.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42