Skip to main content
Known Participant
October 6, 2012
Question

Using cfinclude or cfmodule to include pages that have images?

  • October 6, 2012
  • 1 reply
  • 4183 views

I am at my wits end with this very simple issue.... and I cannot find an answer anywhere using Google search.

I have three files - one is called index.cfm, the other is called companies.cfm and finally one called header.cfm

The header.cfm file contains all my websites header stuff. The image paths I have used are relative so one of them is like this: <img src="images/global/companyLogo.jpg" />

If I use <cfinclude template="header.cfm"> in my index.cfm page then the image displays fine. But if I use the header.cfm file in the companies.cfm file then the image does not display. If I go to view the page source it is still looking for the image using the path "images/global/companyLogo.jpg" when really it should be "../images/global/companyLogo.jpg" to move up a level.

I just can't seem to understand how to do this so that I can use my header.cfm file on any page I want and the relative image paths within that file will resolve correctly.

Please can someone help me because I am so close to giving up and maybe trying a different server side language that can do this simple include function.

    This topic has been closed for replies.

    1 reply

    solacedAuthor
    Known Participant
    October 7, 2012

    Managed to solve this myself..... I used a site root relative path for my images. So rather than just going to a folder where the images are, I made the link path full so it also included the site name:

    SiteName/image/global/logo.gif

    Then it will always work because the path is relative to the site, not the document! God such simple things take so long to figure out.

    Inspiring
    October 7, 2012

    Am I correct in guessing that companies.cfm is not in the same directory as the other two files?  Which means the relative URLs in headers.cfm are not correct when they're being used in companies.cfm?

    Bear in mind that image URLs are relative to the URL or the requested file, not relative to the file the <img> tag happens to be in.

    --

    Adam

    solacedAuthor
    Known Participant
    October 7, 2012

    Yes thats correct, the companies.cfm file was in a different folder. I will end up having many files in different folders but all within the same site of course in wwwroot. So if I am to include a header.cfm file on all my pages then the links and images should display on all pages so the only way is to use site-root relative links NOT document-relative links. This is not explained or suggested anywhere in the CF documentation.