Link to home
Start Free TrialLog in
Avatar of weharlow
weharlow

asked on

problem using cfinclude, image paths and CF Admin mappings

I'm using cfinclude tags. However, the image links are broken when the pages sit in different level folders.  I have used the mapping in the Coldfusion administrator but the images are still broken.  Here is what I have:

In the CF admin mappings:
Logical Path: /include
Directory Path: C:\Inetpub\wwwroot\intranet2\include  

The include tag:
<cfinclude template="/include/include_rightnav.cfm">
is in the following file:
C:\Inetpub\wwwroot\intranet2\departments\health\health_contact.htm

The include file is located in the following path:
C:\Inetpub\wwwroot\intranet2\include\include_rightnav.cfm

The image tag inside the above include file (/include/include_rightnav.cfm):
<img src="images/UCTV16-sm.gif"  />
is located in the following path:
C:\Inetpub\wwwroot\intranet2\images\UCTV16-sm.gif

When I look at the source file in IE this is how the image path is rendered:
<img src="images/UCTV16-sm.gif"/>

Can anyone tell me what I'm doing wrong?? I would very much appreciate it.  I have searched the knowledge base and what I've found is basically what I've done above.

Thanks,
Winona
Avatar of erikTsomik
erikTsomik
Flag of United States of America image

make sure that the image is in there
Avatar of weharlow
weharlow

ASKER

The image is definitely in there.
try not to use mapping but access the file with absolute path
I'm trying to avoid doing that.  I use dreamweaver and I let it set the path so I don't have to manually type in the path.  In dreamweaver if I choose to set  it to Site Root then it puts the localhost root in the image tag which is incorrect once I upload it to the server.
Avatar of gdemaria
no you do not want to use the absolute path, unless for a few minutes to test.

try adding / before images as in..

<img src="/images/UCTV16-sm.gif"/>

Since you are referrings the image as  src="images/..."

that means the folder images needs to be directly under whatever folder you're currently in.
But the images folder is not under your current folder, it's under the root folder.
So to reference back to the root, use the leading /   then the folder path will start at the root not in your current location
Basically, CF Server and IE have different ideas about "relative" and "absolute" paths.

IE: relative is refering to the current URL that the browser is rendering.
     absolute is referencing the site root.

CF: relative is refering to the current template being processed ... not the one that was called by the browser initially, but the current template.
     absolute is referencing the location on the filestructure of the machine (in your case, c:\wwwroot\intranet2\... or those defined in custom mappings in the CF administrator. (such as mapping /include to mean c:\wwwroot\intranet2\include )

However, non-CFM files will not be included in a custom mapping, since IIS/Apache does not ask CF to handle any non-CFM files, it just hands files out as requested by the browser, so virtual mappings set in CF will not affect these requests.

If you are using images that are site-wide (such as part of the page layout, company logo etc, then place them in a standard folder /images which will resolve to c:\wwwroot\intranet2\images, and always reference them as <IMG SRC="/images/...
If you are using images that are specific to a single page, you have the option of keeping them relative to the page (same folder as the index.cfm the browser requested) or place them in a single site-wide folder /images (c:\wwwroot\intranet2\images\...)
Thanks, everyone.  But, I'm just not getting something right.  In addition to what I wrote in my initial question, I've now mapped the image folder as follows:

Logical Path: /images
Directory Path: C:\Inetpub\wwwroot\intranet2\images

And I've changed my image tag to: <img src="/images/UCTV16-sm.gif"  /> and the image link is still broken.  (BTW, I tried this path without mapping too and it did not work.)

Right now I'm using a workaround that I found on dreamweaverforum.info by someone named "lovewebdev."  In my application.cfm file I've created a variable <cfset ccpath = "http://localhost/intranet2"> and then added it to the image path in my include file.  <img src="<cfoutput>#ccpath#</cfoutput>/images/UCTV16-sm.gif"/>.  This is not ideal, but will work okay since I don't have to change images and links often in these include files.  When I move it over to the intranet server I just have to change the path in the application.cfm file.
ASKER CERTIFIED SOLUTION
Avatar of gdemaria
gdemaria
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Aha!  That's the ticket, gdemaria!  wwwroot is my root folder.  I thought I had to map down to the folder the include sits in.  So, I took the mapping out to the images folder, I changed the mapping from /include to /intranet2, added /intranet2 to my img src (src="/intranet2/images/UCTV16-sm.gif") and my include path (<cfinclude template="/intranet2/include/include_rightnav.cfm">) and it works!!

THANKS!
Winona
rendering images to the screen is a web-thing, not coldfusion, so your images (as well as javascripts, and style sheets) are all relative to your web structure (not relative to the place where your coldfusion files are located).   Coldfusion file location is really only applicable when using cfinclude and cfc mappings and such.

But why is your root wwwroot and not intranet2 ?   Seems like you may have intranet1 and perhaps intranet3... arent' they all seperate web sites needing their own root ?

I only have one intranet and I'm redesiging it.  On my localhost, the intranet sits right on wwwroot because I don't develop any other web sites locally.  So, instead of creating 2 separate sites I just created a separate folder (intranet2) to hold the redesigned pages.  Obviously not good form (this issue being a good example).   The live server does have two sites so I will have to change the mapping accordingly.   I'll match the localhost and live server.  I've just never had an issue with it before probably because I've never used include files this extensively.

Thanks again!