5 Replies Latest reply on Jun 4, 2009 6:37 AM by ilssac

    CFINCLUDE relative pathway workaround

    EwokStud Level 1

      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.

        • 1. Re: CFINCLUDE relative pathway workaround
          ilssac Level 5

          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 --->

          1 person found this helpful
          • 2. Re: CFINCLUDE relative pathway workaround
            EwokStud Level 1

            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?

            • 3. Re: CFINCLUDE relative pathway workaround
              ilssac Level 5

              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.

              • 4. Re: CFINCLUDE relative pathway workaround
                EwokStud Level 1

                Please allow me some elbow room to sketch a mental picture; I've never used mappings before.

                 

                Is this correct?

                ferns.cfm located in Root / Plantlife / wilderness

                                           as such:

                Root

                     Plantlife 

                          wilderness

                               ferns.cfm

                 

                 

                This is pretty raw, but having never used mappings before, I feel like a grade schooler.  My punctuation may be off.

                • 5. Re: CFINCLUDE relative pathway workaround
                  ilssac Level 5

                  I'm not sure if that is correct or not, you did not describe a mapping.

                   

                  A mapping looks like this:

                   

                  mappingName = system path.

                   

                  Examples

                   

                  / = c://inetpub/wwwroot

                   

                  /mySite = /export/home/users/webuser/htdocs

                   

                  /cfcs = d://websites/common/components

                   

                  /wilderness= /root/plantlife/wilderness/

                   

                   

                  These can be defined in the ColdFusion Administrator control pannel under Server Settings: Mappings OR as of ColdFusion 8 inside an Application.cfc file.

                   

                  You would then use these in <cfinclude...> tags as the base of a path.

                   

                  Examples:

                   

                  <cfinclude template="/aFile.cfm">

                  This would find c://intpub/wwwroot/aFile.cfm.


                  <cfinclude template = "/mySite/aDirectory/aFile.cfm">

                  This would find /export/home/users/webuser/htdocs/aDirectory/aFile.cfm.

                   

                  <cfinclude template = "/cfcs/models/aComponent.cfc">

                  This would find d://websites/common/components/cfcs/models/aComponent.cfc.

                   

                  <cfinclude template = "/wilderness/ferns.cfm">

                  This would find /root/plantlife/wilderness/ferns.cfm.

                  1 person found this helpful