Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

how to reference a file at a application location?

New Here ,
Dec 09, 2009 Dec 09, 2009

I'm just trying to find a way to reference files for purposes of creating a hyper link, etc.

When using cfinclude for things like a header or footer, the location for the links may not always be accuate in the header and footer templates if you just hardcore the path in. Especially if they're being included from different directories, etc.

So, if I have something like...

  • Web Root/
    • Application.cfc
    • index.cfm
    • Tracker/
      • templates/
        • header.cfm
        • footer.cfm
      • views/
        • index.cfm
        • signout.cfm

... how can I create a hyperlink in header.cfm that always has the correct path to signout.cfm. When a user accesses index.cfm at the web root location, and it does cfinclude index.cfm from the Tracker/views/ directory, the url will be the root url, still. If a user directly accesses the index.cfm from the Tracker/views directory then the url will have that path on it.

Is there a way to do soemthing like #Tracker.views.signout#, and it'll return the explicit path to that file, no matter what page I'm on?

Thanks,

267
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Dec 09, 2009 Dec 09, 2009

You may want to explore the expandPath() function [http://livedocs.adobe.com/coldfusion/8/htmldocs/functions_e-g_05.html].

Note this will be the file system path to the said file.  It would take some messaging before it could be a URL path.

You may also want to eplore the difference between relative and absolute HTML URL paths.

But, really why would you have a different path because in one place you include the content and the other you access it directly?  Normally, in frameworks like you seem to be applying here.  Views are always include where they are needed, thus the path should never matter.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Dec 09, 2009 Dec 09, 2009
LATEST

Using absolute paths in a case like this is almost always best.  Such as /tracker/views/signout.cfm.  This might be a problem if you application is not in the web root for whathever reason, such a development or testing environment.

In that case, you can set a path in Application.cfm:

<cfset RootPath = "/mysite/" />

Then in your header:

<a href=#RootPath#tracker/views/signout.cfm">....

Hope that helps!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources