Skip to main content
Homestar9
Inspiring
December 21, 2017
Answered

CFScript Question: WriteDump() on a new line

  • December 21, 2017
  • 2 replies
  • 3578 views

Is there a way to make writeDump() easily output to a new line when using this within a <cfscript> block?

This topic has been closed for replies.
Correct answer Charlie Arehart

Do you mean because the thing you’re dumping is just a simple variable being output? As opposed to something like a query, struct, array, or CFC where it creates a table of output (implicitly on a new line from whatever was output above it)?

If so, then it seems your answer is “no”.  And this is no different than a CFDUMP. You just have always needed to add an html br tag before or after dumping a simple variable, if you wanted the dumped variable to be on its own line.

Of course, with CFDUMP you could just add that before or after that tag, but with writedump, you’d have to do a writeoutput of a br tag, and I agree that’s annoying.

BTW, someone may want to suggest, why don’t you just do the br tag within the writedump separated with an &. I’ll try it here, but I don’t know if it will render in this forum:

writedump(somesimplevar & "<br>");

That doesn’t work, because the writedump just htmlencodes the output, such that if somesimplevar was = 1, the result would be:

1&lt;br&gt;

Edit: Of course, you could just use writeoutput instead, if you KNEW it was indeed a simple variable. But if your point is that when you do the writedump you don't know if it will be or not, then I can appreciate your challenge here.

So really, this could be a nice feature request for you to add (at tracker.adobe.com), to add an argument to allow for that. (As it stands, the writedump takes all the same arguments as CFDUMP had for attributes, but there was no real need for a CFDUMP attribute like this need you’re describing—but it wouldn’t hurt to have it for CFDUMPs of simple variables also).

/charlie

2 replies

Homestar9
Homestar9Author
Inspiring
December 22, 2017

Thanks Charlie.

I also took a look at the cfDocs (https://cfdocs.org/writedump) and it suggests you can pass a `format` attribute which might do the trick.  Unfortunately it doesn't work for me on ColdFusion 2016.

Non-Working Example:

<cfscript>

myVar1 = "apple";

myVar2 = "banana";

writeDump(

  var = "#myVar1#<br>",

  format="html"
);

writeDump(

  var = "#myVar2#<br>",

  format="html"
);

</cfscript>

This might be a nice thing for Adobe to add as a possible feature in the future.  In the meantime, perhaps a custom UDF will do the trick.

Homestar9
Homestar9Author
Inspiring
December 22, 2017

Note: I created a feature request on the Adobe tracker if anyone else feels this would be a nice addition:

https://tracker.adobe.com/#/view/CF-4200441

Charlie Arehart
Community Expert
Charlie ArehartCommunity ExpertCorrect answer
Community Expert
December 22, 2017

Do you mean because the thing you’re dumping is just a simple variable being output? As opposed to something like a query, struct, array, or CFC where it creates a table of output (implicitly on a new line from whatever was output above it)?

If so, then it seems your answer is “no”.  And this is no different than a CFDUMP. You just have always needed to add an html br tag before or after dumping a simple variable, if you wanted the dumped variable to be on its own line.

Of course, with CFDUMP you could just add that before or after that tag, but with writedump, you’d have to do a writeoutput of a br tag, and I agree that’s annoying.

BTW, someone may want to suggest, why don’t you just do the br tag within the writedump separated with an &. I’ll try it here, but I don’t know if it will render in this forum:

writedump(somesimplevar & "<br>");

That doesn’t work, because the writedump just htmlencodes the output, such that if somesimplevar was = 1, the result would be:

1&lt;br&gt;

Edit: Of course, you could just use writeoutput instead, if you KNEW it was indeed a simple variable. But if your point is that when you do the writedump you don't know if it will be or not, then I can appreciate your challenge here.

So really, this could be a nice feature request for you to add (at tracker.adobe.com), to add an argument to allow for that. (As it stands, the writedump takes all the same arguments as CFDUMP had for attributes, but there was no real need for a CFDUMP attribute like this need you’re describing—but it wouldn’t hurt to have it for CFDUMPs of simple variables also).

/charlie

/Charlie (troubleshooter, carehart. org)