Skip to main content
Participant
December 19, 2010
Question

Changing The Value of the CF Relative Path

  • December 19, 2010
  • 2 replies
  • 962 views

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!

This topic has been closed for replies.

2 replies

Inspiring
December 19, 2010

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

Inspiring
December 19, 2010

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

i69alotAuthor
Participant
December 19, 2010

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?

Inspiring
December 19, 2010

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.