1

I'd like to resolve this problem. I have a variable:

<cfset myvar = "mytext <cfinclude template=""test.cfm"">">

and I have test.cfm with an amount of cfml code.

and I'm trying to make cfoutput like this:

<cfoutput>#myvar#</cfoutput>

I'd like that my page doesn't show this output:

mytext <cfinclude template="test.cfm">

but:

mytext followed by the execution of cfml code inside test.cfm

Is it possible?

user1903894
  • 169
  • 1
  • 1
  • 6

3 Answers3

3

I am not certain what you are trying to do from your question but if my guess is correct this may do what you want:

<cfsavecontent variable="myvar"><cfoutput>
mytext
<cfinclude template="test.cfm">
</cfoutput></cfsavecontent>


<cfoutput>
#myvar#
</cfoutput>

Note: You may not need the cfoutput inside the cfcontent tag, it depends on your page setup so I have just added it.

M.Scherzer
  • 921
  • 7
  • 9
0

I have no idea what your included test.cfm file is doing since you did not share that information but this might work for you:

<cfset myvar = "mytext ">
<cfoutput>#myvar#</cfoutput>
<cfinclude template="test.cfm">

Assuming that the included file generates the output that you are looking for.

Miguel-F
  • 13,450
  • 6
  • 38
  • 63
0

In your code, you are trying to set the cfinclude tag itself to another variable. This will never work. However, I have tested the following on a live server and it does work.

    <cfsavecontent variable="inc">
        <cfinclude template="test.cfm">
    </cfsavecontent>
    
    <cfoutput>mytext #inc#</cfoutput>

In this example, everything between the cfsavecontent tags is saved to a variable, in this case inc. Then you are able to reference that variable in the cfoutput tag.

Or, to use <cfset> as in your code:

<cfsavecontent variable="inc">
    <cfinclude template="test.cfm">
</cfsavecontent>

<cfset myvar = "mytext" & inc>

& is the CFML string concatenation operator.

It's difficult to know for sure without seeing more of your code, but if you are trying to use includes in this way your code is perhaps disorganized. Providing a full example would help provide some context.