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

CFINCLUDE and URL parameters

LEGEND ,
Jun 24, 2019 Jun 24, 2019

Copy link to clipboard

Copied

Hello, all,

Has anyone else had any issues using URL parameters with a CFINCLUDE?

I've got something like:

<cfinclude template="#app_base#common/thisfile.cfm?its=1" />

app_base is a variable that sets the root depending upon what environment I'm in.  In DEV, it's "/public/".  In staging, it's "/preview/public/".  In production, it's "/".

I've got one page that is trying to use CFINCLUDE three times, so the its value changes with each include.

But I'm getting error messages stating that "ColdFusion cannot find /preview/public/common/thisfile.cfm?its=1".  It's there, I can see it in the FTP.

Thoughts?

V/r,

^ _ ^

Views

3.2K

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

correct answers 1 Correct answer

Community Expert , Jun 24, 2019 Jun 24, 2019

I didn't even see that the first time around. That's your problem right there!

CFINCLUDE doesn't work that way. It doesn't execute the other file, then bring its contents back into your file. Instead, it brings the contents of the other file into the including file before the whole thing is then executed. So, if you want to have something like this happen, you have to set a variable in the including file, then reference it within the included file. You could, for example, have something like this

...

Votes

Translate

Translate
Community Expert ,
Jun 24, 2019 Jun 24, 2019

Copy link to clipboard

Copied

CFINCLUDE relies on CF mappings when the first character is a slash. So you'd need to have a mapping for either /preview or / that resolves to the location of the preview directory. You probably already know that, but it's just the first thing that comes to mind here.

Also, I would recommend not having one site nested within another, which is what it looks like you have here. This is an unrelated problem, but just isn't generally recommended.

Dave Watts, Eidolon LLC

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 ,
Jun 24, 2019 Jun 24, 2019

Copy link to clipboard

Copied

Thanks for the quick reply, Dave.

I'll have someone check the mappings, I believe that they are already in place, but I'll double-check.

No sites are nested within another site.  The "/", "/public/", and "/preview/public/" are not only on different servers, but different networks all together.

V/r,

^ _ ^

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 ,
Jun 24, 2019 Jun 24, 2019

Copy link to clipboard

Copied

Dave,

Is this supposed to be done under Mapping?  Or Sandbox Security?  Or both?  (I'm assuming Mapping, but want to be sure.)

V/r,

^ _ ^

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
Community Expert ,
Jun 24, 2019 Jun 24, 2019

Copy link to clipboard

Copied

This should be under Mappings.

Dave Watts, Eidolon LLC

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 ,
Jun 24, 2019 Jun 24, 2019

Copy link to clipboard

Copied

Thank you, Dave.  I've got our SA on it, right now.  I'll test it and report back.  But I have a feeling that I'll be marking your answer as correct in a little bit.  (I honestly thought we already had these in place.)

V/r,

^ _^

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 ,
Jun 24, 2019 Jun 24, 2019

Copy link to clipboard

Copied

We set "/preview" as a mapping in CFAdmin, pointed it to the preview folder, and re-started the service as a precaution.  The page is still erroring, and we are still getting the email message "Could not find the included template /preview/public/common/thisfile.cfm?its=1"

Any other possibilities?

V/r,

^ _ ^

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 ,
Jun 24, 2019 Jun 24, 2019

Copy link to clipboard

Copied

I tested this further by removing the URL parameter from the CFLOCATION, and it works.

????

V/r,

^ _ ^

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
Community Expert ,
Jun 24, 2019 Jun 24, 2019

Copy link to clipboard

Copied

I didn't even see that the first time around. That's your problem right there!

CFINCLUDE doesn't work that way. It doesn't execute the other file, then bring its contents back into your file. Instead, it brings the contents of the other file into the including file before the whole thing is then executed. So, if you want to have something like this happen, you have to set a variable in the including file, then reference it within the included file. You could, for example, have something like this:

<!--- the including file --->

<cfset URL.its = "1">

<cfinclude template="/path/to/thisfile.cfm">

and then ...

<!--- thisfile.cfm --->

<!--- do something with URL.its --->

Sorry I missed that the first time around.

Dave Watts, Eidolon LLC

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 ,
Jun 24, 2019 Jun 24, 2019

Copy link to clipboard

Copied

So, waitaminnit.. you can set a variable in the URL scope in the containing file, and it will be read by the included file?????

That's so intuitive! /s   (SMH)

I'll give that a shot.. thank you for the heads-up.

V/r,

^ _ ^

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
Community Expert ,
Jun 24, 2019 Jun 24, 2019

Copy link to clipboard

Copied

Well, in a certain context, it makes perfect sense. The problem is that you have to be aware of that context to understand why it makes sense. The way CFINCLUDE is supposed to work is almost literal - you are including one file within another. It basically gives you one big file when you're done. So, within that context, of course you can't pass arguments to the included file, because it doesn't make any sense for that file to have URL parameters or any other inputs as it's not being invoked by an HTTP request.

Under the covers, it may not actually even work that way for all I know, but that's the "interface" for how we're supposed to understand CFINCLUDE, or includes in other languages/environments.

Dave Watts, Eidolon LLC

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 ,
Jun 24, 2019 Jun 24, 2019

Copy link to clipboard

Copied

I was under the (apparently incorrect) impression that the containing page would be processed up to the include point, then the included file would be processed separately (same thread, different thread) and the results included, then processing in the containing page would finish.

But the containing page instructions are parsed, then the included page parsed, then the rest of the containing page, THEN the html is built on the fly?  Is that the inner-workings?  Or am I completely misunderstanding the process?  (Wouldn't surprise me if that last one is correct.)

V/r,

^ _ ^

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
Community Expert ,
Jun 27, 2019 Jun 27, 2019

Copy link to clipboard

Copied

LATEST

Well, so this is kind of hard to answer. I literally have no idea how it works internally. But I know how it appears to work from the outside, and how it's supposed to appear to work from the outside, and that's the process I described earlier - the construction of one big file before the contents of the included file are run. This is one of those "interface vs implementation" questions, sort of. The "interface" here is that the included file is included once you get to the CFINCLUDE, but is not treated as a separate file for the process of execution - it's just executed as part of the larger file. I guess you could figure out the implementation a bit by looking for the compiled Java classes and decompiling those to figure out what's going on, but I'm honestly not curious enough to bother doing that.

Dave Watts, Eidolon LLC

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 ,
Jun 24, 2019 Jun 24, 2019

Copy link to clipboard

Copied

My mind is still reeling from how couner-intuitive that all seems.. but it worked!  Thank you!

V/r,

^ _ ^

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