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

CFINCLUDE relative pathway workaround

New Here ,
Jun 03, 2009 Jun 03, 2009

Copy link to clipboard

Copied

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.

TOPICS
Advanced techniques

Views

4.6K

Translate

Translate

Report

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 ,
Jun 03, 2009 Jun 03, 2009

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

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
New Here ,
Jun 03, 2009 Jun 03, 2009

Copy link to clipboard

Copied

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?

Votes

Translate

Translate

Report

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 ,
Jun 03, 2009 Jun 03, 2009

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

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
New Here ,
Jun 03, 2009 Jun 03, 2009

Copy link to clipboard

Copied

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

<HTML> <HEAD> <TITLE>ferns</TITLE> blah blah <CFINCLUDE TEMPLATE="application.cfm/footer.cfm"> </HTML>   and   <HTML> <HEAD> <TITLE>application.cfm</TITLE> blah blah <CFSET "pageFooter/" = Root> </HTML>

 

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

Votes

Translate

Translate

Report

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 ,
Jun 04, 2009 Jun 04, 2009

Copy link to clipboard

Copied

LATEST

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.

Votes

Translate

Translate

Report

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
Documentation