Relative Links in an include file

I am looking for the best way to handle this.  I have an include file in one directory that contains <a>nchor tags to link to other pages.  From that point in the directory structure, everything is working find..but if I reference the include file from a different page in a different directory, of course it does not work.  Is there a best practice regarding this and a way to accomplish this task so that the include file contains relative links to other pages based on where it is included?
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

I think the best way to do is to create an application var that holds the root dir information. such as

application.root = ""

This will allow you to create link files that start at the base directory so you can do

<cflocation url="#application.root#/dir/page.cfm">

Then you can always start from the root regardless of directory
beregothAuthor Commented:
That sounds very reasonable...however, if I use a fully qualified url, like in your example, then I will not be able to test locally and that, for abvious reasons, is a must.  OOh, what about this...set a variable, like you suggest, at the top of every page...when the <cfinclude> file is read in, it will read in that variable to get the relative current position so it knows how many directories levels it needs to go up the chain to get to the correct link....this is basically what you were suggesting, only I won't use the url, I'll use a string like "../../", then when the include file is loaded, it will use a concatenated string to build the url.  One question (assuming you agree I am on the right track) though...will syntax like this work...

application.offset = "../../"

<a href="#application.offset#file.cfm">

if you set application.offset on each page this would work


it is much easier to have this stored in one file and change there.  Not on each page.

say for instance you were doing this in dev on server

you would change the application.root (only while in production) to

<cfset application.root = ""

you will now have your root directory on dev

No need to have this var set on each page

does this make sense???
10 Tips to Protect Your Business from Ransomware

Did you know that ransomware is the most widespread, destructive malware in the world today? It accounts for 39% of all security breaches, with ransomware gangsters projected to make $11.5B in profits from online extortion by 2019.

beregothAuthor Commented:
It makes sense, I just can't seem to get it to work.  In my first page to the site, index.cfm, I put the following code...

<cfapplication name="MikesResume">
<cfset application.root = "//localhost/resume">

(note that I tried the cfset without the cfapplication tag and it said I could not do that...this is new to me so bear with my ignorance).

Later, in the file I want to include I put the following in the <a>nchor tag..

<a href="#application.root#/Employment/otherfile.cfm">

but when I run the app and hover over the link I get some really strange syntax (which does not resolve the #application.root# variable) and when I click on it, nothing error message no nothing.

So while I hope I am understanding your intention...I am wondering if I am still not implementing it correctly.
you need to have an application.cfm file

this file is an independt file that contains all applicaiton var

in this you will set your application file

so you do the following in application.cfm

<cfapplication name="MikesResume">
<cfset application.root = "http://localhost/resume>

now in the href you would need the following

<a href="#application.root#/Employment/otherfile.cfm">click here </a>

this will work


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
the application.cfm file is located in your root dir
beregothAuthor Commented:
That did it!  Thanks so much for spending the time walking me through this...I am obviously a novice to many of the cool features in CF so I really appreciate the effort.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Servers

From novice to tech pro — start learning today.