Copy link to clipboard
Copied
I am trying to create a CFC that will write a file with CFML in it using code like the following example...
<cffile action="write" file="C:\ColdFusion8\wwwroot\T\test.cfm" output="<cfmenu name=""test"">">
but ColdFusion keeps trying to read what is in the output="". Is there any way to make it so that ColdFusion doesn't try to read the output text as CFML?
Yep.
Do it the way I showed you in that other thread. Basically the way to get the CF compiler to not compile CFML instructions which are actually part of a string, rather than code, is to "escape" the tags.
Relevant snippet from other thread:
<cfsavecontent variable="sMenus">
<cfset sCfO = "<" & "cf">
<cfset sCfC = "</" & "cf">
<cfoutput>
#sCfO#menu type="horizontal">
<cfquery name="qMenus" dbType="query">
[snip]
...
Copy link to clipboard
Copied
Yep.
Do it the way I showed you in that other thread. Basically the way to get the CF compiler to not compile CFML instructions which are actually part of a string, rather than code, is to "escape" the tags.
Relevant snippet from other thread:
<cfsavecontent variable="sMenus">
<cfset sCfO = "<" & "cf">
<cfset sCfC = "</" & "cf">
<cfoutput>
#sCfO#menu type="horizontal">
<cfquery name="qMenus" dbType="query">
[snip]
</cfquery>
<cfloop query="qMenus">
#sCfO#menuitem display="#label#" href="#CGI.script_name#?id=#id#" name="sub_#parentId#_#id#">
#getSubmenus(menuData=qMenuData, parentId=id)#
#sCfC#menuitem>
</cfloop>
#sCfC#menu>
Where sCfO and sCfC ("CF open" and "CF close") are variables holding "<cf" and "</cf" respectively. So when creating your string, you have "#sCfO#menu" which will contain "<cfmenu".
Make sense?
--
Adam
Copy link to clipboard
Copied
Ah, I see. Very clever. Thanks. Don't take it personally if I don't copy/paste your code. I like to recode stuff people give me so that I can understand it better and also so it is my own creation.
Copy link to clipboard
Copied
I am trying to create a CFC that will write a file with CFML in it using code like the following example...
<cffile action="write" file="C:\ColdFusion8\wwwroot\T\test.cfm" output="<cfmenu name=""test"">">
but ColdFusion keeps trying to read what is in the output="". Is there any way to make it so that ColdFusion doesn't try to read the output text as CFML?
There is nothing wrong with the code. Coldfusion will read what is in the output attribute as text, and wont try to execute it.
However, you're copying CFML code to the file, test.cfm, which you save as CFM. Hence, when you open the file in the browser, Coldfusion will run it like it would any other CFM file. Nothing special about that. One solution is to escape the tags, as follows
<cffile action="write" file="C:\ColdFusion8\wwwroot\T\test.cfm" output="#htmleditformat('<cfmenu name=""test"">')"#>