Skip to main content
Known Participant
June 3, 2009
Question

CFINCLUDE relative pathway workaround

  • June 3, 2009
  • 1 reply
  • 4897 views

1)  To my knowledge, CF requires a relative pathway for CFINCLUDE pathways.

2)  I have a widely used page footer, that exists on all my pages.

3)  I have a wide variety of subdirectories for my pages.

4) aside from  the ../../../../../.. method, I have found myself nesting CFINCLUDE, with the respective template in each folder, with CFINCLUDE TEMPLATE=../name.cfml referencing the parent folder, and then that template referencing its parent folder, etc.  like this:

Root folder: (Template name is PageFooter.cfml and contains the actual footer code)

     SHRUBS      all pages in this folder contain:

                     <CFINCLUDE TEMPLATE="../PageFooter.cfml"> with PageFooter.cfml containing:

                     <CFINCLUDE TEMPLATE="../PageFooter.cfml">

          EVERGREENS      all pages in this folder contain:

                     <CFINCLUDE TEMPLATE="../PageFooter.cfml"> with PageFooter.cfml containing:

                     <CFINCLUDE TEMPLATE="../PageFooter.cfml">

               NEEDLE      all pages in this folder contain:

                     <CFINCLUDE TEMPLATE="../PageFooter.cfml"> with PageFooter.cfml containing:

                     <CFINCLUDE TEMPLATE="../PageFooter.cfml">

               LEAF      all pages in this folder contain:

                     <CFINCLUDE TEMPLATE="../PageFooter.cfml"> with PageFooter.cfml containing:

                     <CFINCLUDE TEMPLATE="../PageFooter.cfml">

     FLOWERS      all pages in this folder contain:

                     <CFINCLUDE TEMPLATE="../PageFooter.cfml"> with PageFooter.cfml containing:

                     <CFINCLUDE TEMPLATE="../PageFooter.cfml">

          PERENNIALS      all pages in this folder contain:

                     <CFINCLUDE TEMPLATE="../PageFooter.cfml"> with PageFooter.cfml containing:

                     <CFINCLUDE TEMPLATE="../PageFooter.cfml">

          ANNUALS      all pages in this folder contain:

                     <CFINCLUDE TEMPLATE="../PageFooter.cfml"> with PageFooter.cfml containing:

                     <CFINCLUDE TEMPLATE="../PageFooter.cfml">

Now I've heard about using application.cfml to accomplish this task with less agony, by using CFSET somehow, and the use of one template in each folder called global.cfml and that global.cfml references the application.cfml using this CFSET I think.

Pleae help.

This topic has been closed for replies.

1 reply

ilssac
Inspiring
June 3, 2009

The normal ColdFusion solution to this problem is to use ColdFusion mappings.  In previous versions of CF these could only be set up in the administrator as of CF8 one can not set these up within Appliction.cfc files.  This helps with web hosting services where access to the administrator is not handy.

On singe site servers, CF can create a defaut mapping named "/".  But this does not work well for multiple web site servers.  For these you will need to create a more uniqe name for the mapping.  But once you have a mapping set up for the web root of you site, either the basic "/" or something unique like "mySiteRoot", you can use these in your <cfinclude ...> tags.

I.E.

<cfinclude template="/pageFooter.cfml"> <!--- using the basic "/" mapping --->

OR

<cfinclude tempalte="mySiteRoot/pageFooter.cfm" <!--- using the unique "mySiteRoot" mapping --->

EwokStudAuthor
Known Participant
June 3, 2009

Thank you very much.  Currently I am using a third-party server, and uploading my pages to thi sserver a few hundred miles South of my computer....  However, I would need to insure that the version of Cold Fusion being used by my hosting company is MX7 or 8, right?  Will the help you gave me work on earlier versions than MX7, if this server I use (and pay "rent" to) has such an earlier version?

ilssac
Inspiring
June 3, 2009

Using mappings with <cfinclude....> has been part of ColdFusion since at least version 4.5 when I started.

The ability to define these mappings yourself within an Application.cfc file was new to ColdFusion 8.

For older versions you would have to work with your hosting provider to enter the mappings in the ColdFusion Administrator control panal.  Most service provider worthy of the name will have an ability to accomidate this type of request.