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

Changing The Value of the CF Relative Path

New Here ,
Dec 19, 2010 Dec 19, 2010

Copy link to clipboard

Copied

Hi:

Is there a way to change the value of the relative path CF uses when resolving the template attribute of cfinclude? In particular, I'd like to be able to assign the relative path of the calling template of a custom tag to the relative path of the custom tag itself, regardless of where the tag resides. Suggestions welcome. Thanks!

TOPICS
Advanced techniques

Views

828

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
LEGEND ,
Dec 19, 2010 Dec 19, 2010

Copy link to clipboard

Copied

Well: no.  By definition a "relative path" is... well... relative!  IE: relative to where it is being used.

So what you want is just "some path" not a "relative path".

The only way I can think to effect what you want is to pass in a "contextPath" attribute, or something.

Or you could possibly mess around with an Exception object which will have its tag context returned, which should return the path the the file calling the custom tag in the... second (?)... position in the array (the first position being the current file), I guess.  But then you'd have a full file system path, which is no good for a <cfinclude>.

What exactly are you trying to implement here?

--

Adam

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 ,
Dec 19, 2010 Dec 19, 2010

Copy link to clipboard

Copied

Thanks for your reply.

I'm lazy.

I'd like to use <cfinclude template="cf_template_only_no_folder_info.cfm" />, no matter where I'm calling a template from, no matter how many folders deep. This bears the striking resemblance of what a custom tag does, expect the scoping is different, among other things.

You're right, I just need some path, not the relative path. I should also mention that all my templates are within a top level app folder or lower.

Since I first posted this, I've come up with a possible solution, but would still like to hear other ideas. Your opinion is welcome. Here it is...

1) Create a custom tag called inc.cfm. Basic syntax would be <cf_inc template="cf_template_only_no_folder_info" />

2) Code the tag as follows:

<!--- Set the template attribute aside --->

<cfset request.template = variables.attributes.template />

<!--- "Re-scope" the caller variables --->

<cfset variables = StructCopy(caller.variables) />

<!--- Put the template attribute value back in the custom tag scope --->

<cfset variables.template = request.template />

<!--- Now include the template attribute --->

<cfinclude template="#variables.approot#/#variables.template#.cfm" />

I haven't tried this yet, but this or a close version of it should be able to get the job done. Calls to inc.cfm from within inc.cfm itself (via cfinclude) should be accommodated.

What do you think?

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
LEGEND ,
Dec 19, 2010 Dec 19, 2010

Copy link to clipboard

Copied

Just out of curiousity, do you have any other types of re-useable files like javascript or images?  If so, the way you handle those might work for included .cfm files.

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
Guide ,
Dec 20, 2010 Dec 20, 2010

Copy link to clipboard

Copied

Can you not use an application-level mapping? Or any other app-level variable?

Or am I still missing the point of what you're trying to achieve?

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
LEGEND ,
Dec 20, 2010 Dec 20, 2010

Copy link to clipboard

Copied

What do you think?

Bleah is what I think.

And you see this as better than sticking a path into your <cfinclude> calls?

[boggle]

<cfinclude template="#variables.approot#/#variables.template#.cfm" />

This would require all the include files to be stored "flat", in the approot dir?  Is that what you want to do?  In that case, why not just stick 'em all in an /includes/ dir, and hard-code that:

<cfinclude template="/includes/#variables.template#.cfm">

--

Adam

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
LEGEND ,
Dec 20, 2010 Dec 20, 2010

Copy link to clipboard

Copied

LATEST

This is the approach we use for images, stylesheets, javascript, User Defined Functions, and some Includes (headers and footers mainly).

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
LEGEND ,
Dec 19, 2010 Dec 19, 2010

Copy link to clipboard

Copied

For custom tags, you can specify a directory for their home on your admin page.  If you are going to be using shared hosting, I'm not sure, but I think you can specify a home in your Application.cfc.  If your custom tag has to send data back, the caller scope is what you want.

Cfinclude has nothing to do with custom tags.

As Adam asked, "What are you trying to accomplish?"

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