Server Side Includes (ssi) With Asp
|
|
Server Side Includes (SSI) with ASP
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 an example:-
<%
If foobar="yes" then
response.write "YES!"
Else
response.write "NOT YES!"
End if
%>
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:-
<%
Response.Write "executing included code now"
%>
<!--#include file="../includes/someinclude.asp"-->
<%
Response.write "done executing included code"
%>
And here, we give an example of the other method, virtual inclusion:-
<%
Response.Write "executing included code now"
%>
<!--#include virtual="/includes/someinclude.asp"-->
<%
Response.write "done executing included code"
%>
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:-
%lt;%
Page=request.form("page")
%>
<!--#include file="../includes/<%=page%>.asp"-->
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 but I know you will now be itching to get started right away on using include files to even worry about this, so I will cover it in a future article.
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.
Rob Collyer, experienced with 20 years programming knowledge and site administrator of www.webforumz.com - Copyright 2003-2004
|
|
|
Created & Maintained by Empower! CMS Web Sites
Host2Sell Web Hosting | Emarketing Workshops | Site SEO Review | FREE NewsletterWhat Does An Ex-basketball Coach Know About Pulling Web Metrics?
In my previous life.....Actually, my previous JOB life, I was a physical education teacher and the varsity girls basketball coach. This is where I learned about testing, or as my mentors on the internet say, "Pulling Web Metrics."Simply put, pulling metrics is just testing your product ...(related: Web Development)
How To Start Your Own Website
I'm one of those people that always wanted a website, but had no clue as to using the internet. I could check my email and that was about it. I never heard of ISP, FTP or all those other "words".When I discovered that I had the website making program Microsoft FrontPages I was determined to learn something about html. Then when I discovered I could earn some money by having a website I wanted to start yesterday! And here I am, still don't know hardly anything, but I'm running a website! ...(related: Web Development)
How To Make Your Website More Successful? (part I)
Building a website and getting it online is easy. Driving visitors to it is the more difficult part. Most people are not patient enough when it comes to build up traffic. They expect thousands of visitors a week after they go live with their website. But that is not how it works. We share some secrets of how to make your website more successful.A) Provide content: Search engines love content. As...(related: Web Development)
The Disability Discrimination Act (dda) & Web Accessibility
There's been widespread speculation about the new legislation being introduced under the DDA (Disability Discrimination Act), which will ensure that websites are accessible to blind and disabled users. Try to find specific information about it on the Internet and chances are you'll come up empty handed.The RNIB (Royal National Institute for the Blind) and the DRC (Disability Rights Commission), two of the most renowned advocates for the DDA (Disability Discrimination Act) and accessible websites, have no specific information about the laws and what websites specifically need to do in order to meet the legal requirements.So, what does the law state?Part III of the Disability Discrimination Act refers to the provision of goods, faci...(related: Web Development)
Stop Losing Precious Web Site Traffic To The Dreaded World Wide Web Black Hole
You work hard to build traffic to your web page. If you are not doing 1 simple step you are loosing a portion of all your web site traffic to the dreaded World Wide Web Black Hole.We have all seen the dreaded 404 page not found error. This Error happens when you type a web page address into the browser window and the page does not exist on the Web Site. Most Cpanel's enabl...(related: Web Development)
Dreamweaver 8 Preview
August 8 2005, Macromedia announced a release of Studio 8. Based on the feedback of previous users, Macromedia made it's already very powerful software even better.Dreamweaver 8 improvements include: CSS panelWith the new CSS panel it is very easy to add, view and edit CSS styles.XML integrationIn Dreamweaver 8 you ...(related: Web Development)
What Works And What Not Works For Your Internet Business
"Build it and they will come."
--Filed of Dreams (1989)
If you are working on an Internet business, you may read a lot of information for how quickly you can make money online. The truth is that running online business is same as running traditional business. You need spend time to learn, to build your business. There is no "magic button" you can push and get quick money. But Internet business has larger potential compare to traditional business since you have global customers. If you follow right roadmaps,...(related: Web Development)
How To Promote Your Law Firm Website On The Internet For Maximum Profit
Making maximum profit from your law firm website is important, but as a lawyer you might not have any clue about search engine optimization and Internet marketing for your legal site. However, it is not so difficult to poise your website to be successful online even if you are not experienced with Internet marketing and driving website traffic. All you have to do is review the following tips and include them in your website marketing plan. Before you know it you will notice that your website counter is recording more hits per day and telling you that your directories, keywords, and links are working.Tip #1 - Submitting to Law DirectoriesTake some time online to orient yourself with the myriad of law directories available. Register your domain name and the type of law you practice with as many law directories as you possibly can. By ...(related: Web Development)
High Quality Website At Low Cost
Although designing a great web site is an important part of developing a successful online business, it is often becomes a problem for newcomers to the internet business.The vulgar problem is the lack of money. It usually costs from $500 up to $3000 or even more to develop a professional perfect looking website; but what to do if you don't have such a lamp of money?Of course you can make the...(related: Web Development)
How One Word Or Even One Letter Can Boost Conversion Rates By Over 400%!
Recently I was reviewing the keyword specific conversion rate data of a consulting client of mine. I have been working with this client...(related: Web Development)
site-map - Copyright © 2006 Empower! Web Design | All Rights Reserved. | Web Development
