Forum Moderators: open
For ASP, I'm not quite as well versed. I did a search on ASP includes and tried it out, but something is not working.
I'm hoping someone can help.
Let's suppose I want to include header.asp and footer.asp in index.asp. Could someone show me the code? Would it be any different on .aspx pages?
Thanks
You can use file or virtual, where file is the relative path to file from ASP page; and relative is the root relative path to the file.
If you are still having problems, have a look at the pathing, and if you are still having problems a code snippet of the include call you are using may help!
<edit>Typo fix</edit>
[edited by: BlobFisk at 6:05 pm (utc) on April 10, 2003]
<!-- #include virtual="/html-header.asp" -->
Page content goes here....
<!-- #include virtual="/html-footer.asp" -->
The first include has everything up to where your page content starts.
The last include has everything from the end of your conent to the end of the document.
It's amazing what you can do in between.
I hope that's what you're looking for... my sample is a very stripped down version of what I use on several busy websites.
Don't understand why you'd want to include the <head> tags in an include file (as they'll be different on every page), but there's no reason why it shouldn't work with server.execute("page.asp").
Go ahead and close with a </head> in your include or header file.
At this point, you'd think that would be the end of that, and you wouldn't be able to specify different meta content for the different pages of your site. However...
Go ahead and place content specific meta content after your include declaration. This meta content will over-ride what appears in your header/include. In other words, you can declare meta content outside of your <head></head>.
Make sense?
I do this so that, some pages where I don't specify meta content (cause it's just not really needed) get the generic title and meta. However, the pages where I need to get specific get additional meta content as needed.
This works so long as you've got the .asp or .aspx extention. I don't know about php.
<%@ Language=VBScript %>
<% Option Explicit %>
<!-- #include virtual="/header.asp" -->
<title>ASP Test</title>
Page content goes here.... <!-- #include virtual="/footer.asp" -->
This does not work:
<title>ASP Test</title>
<%@ Language=VBScript %>
<% Option Explicit %>
<!-- #include virtual="/header.asp" -->
<title>ASP Test</title>
Page content goes here.... <!-- #include virtual="/footer.asp" -->
I tried moving around the title tag and also enclosing it in head tags, but nothing worked. What gives?
You can use static & dynamic meta, in the head with 2 headers - (put your option explicit/doctype in header1)
<!-- #include virtual=/header1.asp -->
<static title ...
<static metas ...
<!-- #include virtual=/header2.asp -->
Content here
<!-- #include virtual=/footer.asp -->
<%@LANGUAGE="VBScript"%>
<%Option Explicit%>
<%
'(This makes sure that the user receives a fresh version of the page)
Response.Expires="-100"
%>
<HTML>
<HEAD>
<BASE HREF="http://www.mydomain.com">
</HEAD>
<BODY>
<!--#include virtual="/include/header.asp" -->
<TABLE CELLPADDING="0" CELLSPACING="0" BORDER="0" WIDTH="100%">
<TR>
<TD></TD>
</TR>
</TABLE>
<!--#include virtual="/include/footer.asp" -->
</BODY>
</HTML>
---
Make a separate directory for your include files named "include".
(You'll be glad you did int he long run.)
As a rule of thumb, do this with all the separate "elements" of your web site. Images go into an image dir, Flash in a flash dir, includes..., ect.
Now set a base URL within your <HEAD> tags. Leave out the last "/". Now every image or link within your site needs to be like this...
<IMG SRC="/images/image.gif" WIDTH="##" HEIGHT="##" BORDER="0" ALT="">
<A HREF="/page.asp">This is my link!</A>
...with a preceeding forward slash.
Things will now be more organized and easier to maintain in the future...especially as it expands in content.