Skip to main content
WolfShade
Legend
June 24, 2019
Answered

CFINCLUDE and URL parameters

  • June 24, 2019
  • 1 reply
  • 4863 views

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,

^ _ ^

    This topic has been closed for replies.
    Correct answer Dave Watts

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

    ????

    V/r,

    ^ _ ^


    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

    1 reply

    Community Expert
    June 24, 2019

    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

    Dave Watts, Eidolon LLC
    WolfShade
    WolfShadeAuthor
    Legend
    June 24, 2019

    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,

    ^ _ ^