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

problem with includes...this doesn't make sense

Status
Not open for further replies.

OccasionalCoder

Technical User
Sep 26, 2005
36
US
I have the following directory structure:

Consortium (folder)
index.cfm (file)
header.cfm (file)
admin (folder) Mainmenu.cfm (file)
agency (folder)
content (folder)
fellows (folder Add_fellows.cfm (file)
images (folder)

In the add_fellows.cfm file I have included the header.cfm file and it works ok (using CFInclude template="../../header.cfm)

In the mainmenu.cfm file I include the header.cfm file using ../header.cfm and the header file is included, but the links to images in the included file are broken.

Why does it work in the fellows folder and not in the admin folder?

THanks
 
Because in your header.cfm file, the image tags are looking for images "images/name.jpg". If it's included in add_fellows.cfm, the images aren't in "images/name.jpg", they're in "../../images/name.jpg". You'll either need to put a copy of the image folder in the "Fellows" folder, or change the code in the header to reflect the correct location.

Hope This Helps!

ECAR
ECAR Technologies, LLC

"My work is a game, a very serious game." - M.C. Escher
 
But the header.cfm include worked ok in the add_fellows.cfm file. It doesn't work in the mainmenu.cfm file which is one level above the add_fellows.file.

Thanks again.
 
Write a variable in application.cfm called Set that variable to Use that variable in every img, href, and cflocation tag.

The includes are working fine, it's your html that is not working.

use a coldfusion mapping to use an absolute path to your includes. You can then use something like

<cfinclude template="/yourmapping/header.cfm">

no matter what folder you are in.


As far as your issue with ../ for one level and ../../ for two levels, check that everything is spelled correctly. It should work just fine.
 
Then move a copy of your images folder there, too. Or, along the lines of what imstillatwork suggested, just use your web address for the source of all of your image tags. Then it won't matter what directory they're in.
Code:
<img src"[URL unfurl="true"]http://www.yourwebsite.com/images/name.jpg">[/URL]


Hope This Helps!

ECAR
ECAR Technologies, LLC

"My work is a game, a very serious game." - M.C. Escher
 
Just to elaborate on what ECAR said...

The reason they're broken is because you use relative path locations. Included files do not look at the position they're kept, the take the properties of the includING file.

For example

if you have header.cfm on root folder that link to images using a relative path 'images/myImage.jpg' it will work for any file including it in the same folder. however if you include it from a folder 3 deep the relative path looks from the including file's position, not header.cfm.
so if you have and it includes header.cfm which links to images in 'images/myImage.jpg' the page will look in for the file, not the as you would expect.

imstillatwork's suggestion will create an absolute path. absolute paths don't change despite how deep your folder is.

We've heard that a million monkeys at a million keyboards could produce the complete works of Shakespeare; now, thanks to the Internet, we know that is not true.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top