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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Refering to .js files in another folder using cfinclude

Status
Not open for further replies.

Lotruth

Programmer
May 2, 2001
133
US
I hope no one looks down on me because of this, but I am trying to use a free dhtml script from another website that creates a top menu for my web page. I have a menu.cfm file which contains references to .js files located in the same folder like <script language="javascript" src="menu.js">. It works fine in the folder. I include the menu at the top of my pages using <cfinclude template="menu.cfm">. Again, this works fine as long as i'm in the folder. I have other pages in subfolders like with the menu.cfm file included at the top, but here the menu does not show up because there is no copy of the menu.js file in the names folder. My question is how can I get the menu.cfm file to refer to the menu.js file in the folder instead of looking for a copy of it in names folder? Thanks.
 
Try this:
Code:
<cfinclude template="../menu.cfm">
It tells it search up one level for the menu.cfm file.



Hope This Helps!

Ecobb

&quot;My work is a game, a very serious game.&quot; - M.C. Escher
 
You should probably remove the .. and use the exact path to the .JS file. Using ../menu.js will only work one level down.

Try setting an explicit path:
<cfinclude template="/JS/menu.cfm">
 
I tried both of these methods and neither one of them worked.
 
Well, it's going to depend on your directory structure. Where exactly is the file located in relation to where you currently are in the site? That's where you have to point to. We didn't give you an answer to copy and paste, we gave you the concept so you could modify it to your needs. If the file is two directories up, use "../../" instead of "../". Or, as thedrider suggested, just put the actual full path in every time you reference it. Or, you could add a virtual directory on your web server to every folder pointing back to the original location.



Hope This Helps!

Ecobb

&quot;My work is a game, a very serious game.&quot; - M.C. Escher
 
It could also help to use am application.cfm file. You can then set a root directory and run everything from there. Try something like this...


In application.cfm:

<cfset ProjectRoot = "/MainSiteDir">
<cfset ScriptRoot = "#ProjectRoot#/Scripts"


In any file needing script access:

<script ... src="#ScriptRoot#/menu.js"></script>


This will also let you move the entire site and have all includes still work after chaning the ProjectRoot value.

Dave
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top