Skip to main content
April 8, 2009
Answered

How to include a template from a different directory

  • April 8, 2009
  • 2 replies
  • 1041 views

Hi,

I have a page navigation menu that I placed in a template file.  All the browsing files would then call this template file using cfinclude. 

I now want to call this file from a different directory.  However, this causes all the url and image links to be wrong because the template file uses relative path off of root directory.

I have looked at using cfmodule, but it seems that I would have the same issues unless I make the paths absolute, which I am trying to avoid.

I also thought of prepending to every link in the template file with a directory prefix variable which I passes from the calling files.

Is there an easy and better way to solve this?

Thanks!

Min

This topic has been closed for replies.
Correct answer davidsimms

Simple. Use root-relative links, not relative links, in the included file.

2 replies

davidsimms
davidsimmsCorrect answer
Inspiring
April 10, 2009

Simple. Use root-relative links, not relative links, in the included file.

April 10, 2009

Hi David,

I didn't know what a root relative links was, so I looked the term up.  That is exactly what I need.  Thank you very much!

Min

Inspiring
April 8, 2009

To dynamically get the absolute path from a relative path take a look at expandPath()

http://livedocs.adobe.com/coldfusion/8/htmldocs/functions_e-g_05.html