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

Trouble writing CFML to a file

Guest
Sep 18, 2009 Sep 18, 2009

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?

TOPICS
Advanced techniques
764
Translate
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

LEGEND , Sep 18, 2009 Sep 18, 2009

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]

            

...
Translate
LEGEND ,
Sep 18, 2009 Sep 18, 2009

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

Translate
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
Guest
Sep 18, 2009 Sep 18, 2009

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.

Translate
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 ,
Sep 19, 2009 Sep 19, 2009
LATEST

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"">')"#>

Translate
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