Copy link to clipboard
Copied
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
...Copy link to clipboard
Copied
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<br>
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
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
Note: I created a feature request on the Adobe tracker if anyone else feels this would be a nice addition:
Copy link to clipboard
Copied
If you want to see the value of a simple variable you could do something like this:
writeOutput('myVar1="' & myVar1 & '"<br>');
Cheers
Eddie
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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" 🙂