Search code examples
coldfusioncfml

cfsavecontent from CFML to cfscript


I'm trying to write a savecontent in cfscript.

I have it in CFML:

<cfsavecontent variable="errortext">
    <cfoutput>
        An error occurred: http://#cgi.server_name##cgi.script_name#?#cgi.query_string#<br />
        Time: #dateFormat(now(), "short")# #timeFormat(now(), "short")#<br />

        <cfdump var="#session#" label="Session">
        <cfdump var="#error#" label="Error">
        <cfdump var="#form#" label="Form">
        <cfdump var="#url#" label="URL">

    </cfoutput>
</cfsavecontent>

I need it in cfscript, but how can I do it? Can I put everything inside WriteOuput()?

Thanks

Example not working:

<cfscript>
  local.test = "TEST";
  local.OK = "OK";
  savecontent variable="contentViaScript" {
    writeOutput(
      "String Message:  <br />"
      writeDump(local);
    );
  }
  writeOutput(contentViaScript);
</cfscript>

<cfdump var = '#contentViaScript#' />

Solution

  • You don't need to wrap writedump in writeoutput.

    <cfscript>
      local.test = "TEST";
      local.OK = "OK";
      savecontent variable="contentViaScript" {
        writeOutput("String Message:  <br />");
        writeDump(local);
      }
      writeOutput(contentViaScript);
    </cfscript>
    
    <cfdump var = '#contentViaScript#' />
    

    DEMO