Better way to set Dynamic Directory References?

I have several projects set up in the following directory structure:



\ (contains index.cfm and application.cfc)
\cfc (contains all CFCs)
\html (contains all non home page files)
\images
\includes
\config
(and so on)....

The application.cfc uses REQUEST variables to reference the page location to link to based on where the location is. This is not very good practice, but is an ancient holdover from CF5 when I first started in Coldfusion.

Here is an example:


<!--- if page location anywhere but root--->
<cfif findnocase('html/',cgi.script_name) gt 0 or
findnocase('includes/', cgi.script_name) >

<cfset request.includes='../includes/'>
<cfset request.html="../html/">
<!---(... and so on )--->
<cfelse>
<cfset request.includes='includes/'>
<cfset request.html="html/">
<!---(... and so on )--->
</cfif>

Then I use the reference:



<a href='#request.html#page.cfm'>NavLink1</a>

in my includes and pages to reference given page.

There has got to be a better way to skin this animal. While I am plowing through beans and configs, in the meantime I have several projects that I just want to perform some simple cleanup on.

Anyone got any better suggestions? The settings would need to change based on a page by page basis but aren't updated or reset by the user .

A

Comments (Comment Moderation is enabled. Your comment will not appear until approved.)
Daniel Sellers's Gravatar Try something like this:

<cfsavecontent variable="content">
<cfinclude template="/includes/Header.cfm">
<cfinclude template="#targetPage#">
<cfinclude template="/includes/footer.cfm">
<cfabort>
</cfsavecontent>
<cfoutput>
#content#
</cfoutput>

Place the code in your application.cfc/cfm and modify directories as needed and you are ready to rock...

Also not the prettiest solution though it works
# Posted By Daniel Sellers | 1/15/09 12:57 PM
Daniel Sellers's Gravatar should have read your post again... The above won't help you on a page by page basis... I wouldd have to spend some more time thinking about that one...
# Posted By Daniel Sellers | 1/15/09 12:58 PM
Tami's Gravatar @Daniel,
Thanks, and I have used this approache before, but it doesn't allow me to dynamically determine a relative path based on the current file's location. I want to keep that functionality, but use something more elegant than so many request variables for directory structure.
# Posted By Tami | 1/15/09 1:02 PM
todd sharp's Gravatar Unless I'm missing something, why not just use the full path?

href="/includes/whatever/page.cfm"
# Posted By todd sharp | 1/15/09 1:03 PM
Tami's Gravatar Well, I can use full path. However, these projects are mostly set up using Contribute for the end clients to edit non-db pages. I still want to keep the site nice and tidy by separating the files in proper directories, but wanted a way for the home page to be at the root directory and the underlying pages to be in the \html directory. If I hard code the directory structure into a DW template (for contribute) this often breaks the location.
# Posted By Tami | 1/15/09 1:07 PM
BlogCFC was created by Raymond Camden. This blog is running version 5.9.1.002. Contact HHWD