Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Newbie question - mapping my CSS file from different directory levels 1

Status
Not open for further replies.

sailingfree

Programmer
Sep 13, 2006
32
GB
Hello,

I'm building a website using .asp pages, only because I know a very small amount of ASP and have used a few simple commands to my benefit.

One such command I have now forgotten! I haven't used it in years but it's a really simple problem and I'm hoping someone can answer this in 2 seconds:

My website's index file sits at the root, my CSS file sits in its own directory and all my other pages will sit in their own direstories too. When I view my index page everything displays ok but when i drill down into a page in its own directory, images and so on are missing, because I'm now in a dir lower than my root.

I seem to remember using a really simple asp command that I stick at the top of my page that's a short-cut for the full address and then use this on all my links.

Could someone remind me what this is and how I use it?

Thank you!
 
Don't I put something like

Code:
<% virtualpath="[URL unfurl="true"]http://www....."[/URL] %>
at the top of the page and then write
Code:
<% virtualpath= %>
just before the link in question?

Please, this must be a real simple question for you asp experts to answer!

Thanks
 
I'm still on my first cup, so I may be missing something.

From your example above it look slike your declaring a variable that will hold the path, then later just using that variable. This is a workable method.

When you define images in your CSS file, those image paths should be relative to the directory the CSS file is in. If your outputting relative image paths directly in your HTML/ASP then, yes, the path will need to change for each directory. Unless you use either a full URL (such as your example above) or use a URL based on the root path of your web site.

For instance:
Say we have the following files:
index.asp
pages/index2.asp
pages/somesub/index3.asp
images/mypic.jpg

To display that image in each page, without defining a differant address for each IMG tag, you could do the following:
Code:
[b]Path Based On Root[/b]
<img src="/images/mypic.jpg" />

[b]Path based on URL[/b]
<img src="[URL unfurl="true"]http://www.mydomain.com/images/mypic.jpg"[/URL] />

Now, if you have an include file that you plan on including into every file, than it would be a good idea to put a portion of the file path into the include file as a variable, like you have above. This will shorten the
[/code] number of changes you would need to make if you need to move the site or change the name of your images directory. That would look something like:
Code:
[b]includeFile.asp[/b]
<%
CONST IMAGE_PATH = "[URL unfurl="true"]http://www.mydomain.com/images/"[/URL]
'or
'CONST IMAGE_PATH = "/images/"
%>
Then anywhere you need that path you just make sure you have included this file and output your IMG tag using that variable to help build the path:
Code:
[b]index.asp[/b]
<%
Option Explicit
%>
<!-- #include file="includes/includeFile.asp" -->
<%
'...lots of asp
%>
<img src="<%=IMAGE_PATH%>mypic.jpg" />

you can use File or Virtual to build the path for your includefile, hopefully you will have more uses for it then just to hold this variable. One use I often have for a general include file is to build two functions, ShowHeader and ShowFooter that hold the header and footer HTML for my page. That way I can call the functions when I need to display them in an ASP page and if I ever need to modify them I just modify the one copy in my include file.

Hope this was what you were looking for,
-T

 
Tarwn,

That last bit of code is P R E C I S E L Y what I was looking for.

I used to program with some guys who knew their ASP but I knew very little. However after I left them I continued to use this really simple and obvious command for some years and then I forgot it. It must be so obvious to an asp-programmer but you have saved me hours of searching on the net for this solution.

Star to you!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top