• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 707
  • Last Modified:

CFINCLUDE syntax with #variables#

While, with a previous question, I have resolved issues of having a "root" variable so that references are made much simpler...I have found that the following command would not work (assume #app.root# is defined in an application.cfm file already and set to the proper directory)...

<cfoutput>
<cfinclude template="#app.root#/identity_yellow.cfm">
</cfoutput>

I am constantly told that the include file cannot be found...so I tried...

<cfoutput>
<cfset app.ident = "#app.root#/identity_yellow.cfm">
</cfoutput>

then later...

<cfoutput>
<cfinclude template = "#app.ident#">
</cfoutput>

but that does not seem to work either.

What I am basically tried to do is use the same variable I use in other places for reference purposes to help point to the proper location for include files.

Anyone have any ideas why this does not work?
0
beregoth
Asked:
beregoth
  • 10
  • 6
  • 2
  • +2
1 Solution
 
nathansCommented:
You can only use a relative path therefore there is not a current solution to what you want.  You can not hard code a file or http path.
0
 
beregothAuthor Commented:
boo.  I will wait a little longer before awarding you the points to see if anyone contradicts you...otherwise, I will award you the points.
0
 
nathansCommented:
Sorry for the bad news...


Even when you do the below it does only a relative link.


<CFSET INCLUDES = "../includes">
<CFINCLUDE template="#includes#/footer.cfm">


The instant it is not relative it warns you with a error message that you can not have a hard coded link or some such wording.


www.nsnd.com

Hope I am wrong I would use it for things as well.

0
[Webinar] Improve your customer journey

A positive customer journey is important in attracting and retaining business. To improve this experience, you can use Google Maps APIs to increase checkout conversions, boost user engagement, and optimize order fulfillment. Learn how in this webinar presented by Dito.

 
OeilNoirCommented:
i think nathan is right, i had that problem before too while trying to include
an error page when the users didn't had the required access level or were not logged. Since that page could be called from anywhere. i fixed the problem by copied the error files in all directory where it could occure...
0
 
deepchandaCommented:
You can map the virtual path that you are trying to include to a physical path using CF admin. For instance, you have
<cfinclude template="#app.root#/identity_yellow.cfm"> where
#app.root# = '/root" which maps to C:\source\root. Then you can use #app.root# all across your application to point to  that particular physical location on your server.

DC

0
 
beregothAuthor Commented:
I am not sure I follow...I have tried the syntax

<cfoutput>
<cfinclude template="#app.root#/file.cfm">
</cfoutput>

but it does not work..if you view the source, it never resolves the variable.  Are you suggested something else...sorry to be so dense if this is obvious.
0
 
maneshrCommented:
the path to your cfm file is relative to the webserver root.

Eg

your webserver is in

/www/xyz/ (so www.something.com maps to it)

and file.cfm is in /www/xyz/enterprise-80/lib/file.cfm

then you can use the template as

/enterprise-80/lib/file.cfm.

which would be as good as saying (www.something.com/enterprise-80/lib/file.cfm)


0
 
beregothAuthor Commented:
So If I am understanding this comment correctly...just using a /dir/file.cfm as my pointer to the file I want to include will get me the file from any sub-directory level anywhere else on the site?  That seems too easy...and is this a trick only available for use with <cfinclude>?
0
 
maneshrCommented:
that's right, as long as that /dir is relative to your webserver root.

This is as per CF manual.......

When ColdFusion searches for included files as follows:

* Checks the directory in which the current page lives.
* Searches directories explicitly mapped in the ColdFusion
   Administrator for the included file.

Eg. <CFINCLUDE TEMPLATE="/cfdocs/main.htm">

in fact CFMODULE does somthing similar too...
                 CFMODULE
                                                                             
           
           
Use CFMODULE to invoke a custom tag for use in your ColdFusion
application pages. CFMODULE can help deal with any custom tag
name conflicts that might arise.

Use the TEMPLATE attribute to name a ColdFusion page containing
the custom tag definition, including its path. Use the NAME attribute to
refer to the custom tag using a dot notation scheme indicating the
location of the custom tag in the ColdFusion installation directory.
                                                                             
           
           
                    Syntax
                                                                             
           
                       <CFMODULE TEMPLATE="template"
                           NAME="tag_name"
                           ATTRIBUTECOLLECTION="collection_structure"
                           ATTRIBUTE_NAME1="value"
                           ATTRIBUTE_NAME2="value"
                           ...>


                       TEMPLATE

Used in place of NAME, defines a path to the application page (.cfm
file) implementing the tag. Relative paths are expanded from the current
page. Physical paths are not allowed. Absolute paths are expanded
using the ColdFusion mappings.

                       NAME

Used in place of TEMPLATE, defines the name of the custom tag in the
form "Name.Name.Name..." that uniquely identifies a subdirectory
containing the custom tag page under the root directory for CF custom
tags. For example:

                       <CFMODULE Name="Allaire.Forums40.GetUserOptions">

Identifies the page GetUserOptions.cfm in the directory
CustomTags\Allaire\Forums40 under the root directory of the
ColdFusion installation.

                       ATTRIBUTECOLLECTION

Optional. A structure that contains a collection of key-value pairs that
represent attribute names and their values. You can specify as many
key-value pairs as needed. However, you can specify the
ATTRIBUTECOLLECTION attribute only once. See Usage for moreinformation.

                       ATTRIBUTE_NAME

Optional. Attributes you want your custom tag to use. You can use as
many attributes as needed to specify the parameters of a custom tag.
Each
                                                                             
           
           
                    Usage
                                                                             
           
                       You can use ATTRIBUTECOLLECTION and ATTRIBUTE in the
                       same call.

                       Within the custom tag code, the attributes passed with
                       ATTRIBUTECOLLECTION are saved as independent attribute values
                       with no indication that the attributes were grouped into a structure by
                       the custom tag's caller.

                       Likewise, if the custom tag uses a CFASSOCIATE tag to save its
                       attributes, the attributes passed with ATTRIBUTECOLLECTION are
                       saved as independent attribute values with no indication that the
                       attributes are grouped into a structure by the custom tag's caller.




                                 



                                                                             
           

                                                                             
           
                                           AllaireDoc@allaire.com
                                           Copyright ) 1998, Allaire Corporation. All rights reserved.


0
 
beregothAuthor Commented:
Ok..I think I am starting to get it.  However I think the problem is with the webserver root mapping.  I am using this on personal web server and I have a virtual site created that points directly to the root directory beneath E:\INETPUB\WWWROOT so the virtual directory is is called \RESUME and it points to E:\INETPUB\WWWROOT\MYCOMPANY\RESUMES\MIKE and this is where the "root" of this site application really is located.

If I preclude my include template name with

\RESUME\TEMPLATES\FILE.CFM

it does not work, but if I set it to

\RESUMES\MIKE\TEMPLATES\FILE.CFM

it works fine...but this does not seem to jive with what you are saying, or at least with how my server root must be configured.

Ultimately, this is probably not how the site should be configured...it should be off the root...I am going to try that now but if you have any advice on the configuration of the webserver root that I should be familar with, please don't hesitate to enlighten me....

oh, and according to the manual CFMODULE is an alternative...is it one I should be investigating rather than CFINCLUDE?
0
 
maneshrCommented:
i would suggest that you use the current approach that you are working with, since CFMODULE also expects a template name.

Besides the S/W developers adage "if it aint broke, dont fix it"


Best luck to you!!
0
 
beregothAuthor Commented:
Well pardon the french but now things have gone to hell in a handbasket.  I moved the RESUME directory and everything beneath it to my WWWROOT directory and I can't browse anything from within CF but if I point my browser to localhost\Resumes\index.cfm, it shows the file just fine...what did I break?
0
 
beregothAuthor Commented:
Well pardon the french but now things have gone to hell in a handbasket.  I moved the RESUME directory and everything beneath it to my WWWROOT directory and I can't browse anything from within CF but if I point my browser to localhost\Resumes\index.cfm, it shows the file just fine...what did I break?
0
 
maneshrCommented:
i think the localhost\Resumes\index.cfm is ok, since localhost = WWWroot

you need to change the path in CFINCLUDE to "/Resumes/whatever.cfm".

what is the path to your template in the CFINCLUDE tag now?

0
 
maneshrCommented:
i think the localhost\Resumes\index.cfm is ok, since localhost = WWWroot

you need to change the path in CFINCLUDE to "/Resumes/whatever.cfm".

what is the path to your template in the CFINCLUDE tag now?

0
 
beregothAuthor Commented:
it is pointing to TEMPLATES/WHATEVER.CFM which is the way I was doing it (since the host file is in the root directory...but that is not the problem...now I get a 404 error when I try to browse any file in the browser in the studio or if I click on the preview in browser button...the url it thinks it is supposed to go to is..

http://gkar/Resumes/MikeCraig/summary.cfm

where gkar is my local server, Resumes is supposed to be a virtual directory is PWS to /RESUMES/MIKECRAIG so saying Resumes/MikeCraig is redundent but if I edit the url in ie manually and take out the mikecraig part, the browser find the file just fine...and the change to include /TEMPLATES/WHATEVER.CFM still does not work.

This is aggrevating.  I really think a development mapping is messed up..any suggestions on that?
0
 
beregothAuthor Commented:
it is pointing to TEMPLATES/WHATEVER.CFM which is the way I was doing it (since the host file is in the root directory...but that is not the problem...now I get a 404 error when I try to browse any file in the browser in the studio or if I click on the preview in browser button...the url it thinks it is supposed to go to is..

http://gkar/Resumes/MikeCraig/summary.cfm

where gkar is my local server, Resumes is supposed to be a virtual directory is PWS to /RESUMES/MIKECRAIG so saying Resumes/MikeCraig is redundent but if I edit the url in ie manually and take out the mikecraig part, the browser find the file just fine...and the change to include /TEMPLATES/WHATEVER.CFM still does not work.

This is aggrevating.  I really think a development mapping is messed up..any suggestions on that?
0
 
beregothAuthor Commented:
Ok...I got it...I don't know why but the PWS virtual directory was interfering with things.  As soon as I deleted it, everything was relatively back to normal .... and now I understand what you are talking about...even though I thought RESUME (the virtual directory) was my root, it was not so I need to fully qualify the path for the include after the root (//gkar in my previous comment or my web root url in the real world..after the .com)...now everything is happy.  Thanks for the perserverence...my thick head gets in the way sometimes.
0
 
beregothAuthor Commented:
Thanks for sticking with me on solving this issue.
0
 
maneshrCommented:
no problem..

Happy to hear that your problem was resolved.

Rgds
0

Featured Post

Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

  • 10
  • 6
  • 2
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now