Is there a way to make writeDump() easily output to a new line when using this within a <cfscript> block?
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:
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).
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.
myVar1 = "apple";
myVar2 = "banana";
var = "#myVar1#<br>",
var = "#myVar2#<br>",
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.
If you want to see the value of a simple variable you could do something like this:
writeOutput('myVar1="' & myVar1 & '"<br>');
Eddie, good thinking, if indeed all one is outputting is a simple variable...and assuming the OP wasn't already aware of that function. 🙂
I had presumed (see my first reply above) that he was using writedump because sometimes the variable being dumped might be complex and sometimes might be simple. And I have just edited that first reply to stress that point.
Well, I would not have expected that format="html" to have changed anything. Indeed, it's the default.
To be clear, the format attribute as added to CFDUMP in CF8, as a part of several improvements, one of which was to be able to write the output to a file rather than just to the screen. And the html format was to keep the dump looking like it does (so is the default). The other format value, "text", was introduced to make complex variable dumps look more readable when written to a file --so "not html" 🙂