Did you know there is a “format” attribute for the cfdump tag? The default format is html, but you can also pass in a format of “text”. I’ve found this useful for putting data structures into plain text emails, logs files, and other things.

For example, this code:

<cfset tmp.fname = "John">
<cfset tmp.lname = "Smith">
<cfset tmp.age   = 26>
<cfset tmp.city  = "Omaha">
<cfset tmp.state = "Nebraska">
<cfdump var="#tmp#" format="text">

Produces this output:

struct
AGE: 26
CITY: Omaha
FNAME: John
LNAME: Smith
STATE: Nebraska

It works for complex structures, too:

<cfset tmp.person1.fname = "John">
<cfset tmp.person1.lname = "Smith">
<cfset tmp.person1.age   = 26>
<cfset tmp.person1.city  = "Omaha">
<cfset tmp.person1.state = "Nebraska">
<cfset tmp.person1.pets  = ['Fluffy','Mr. Jingles','Bambi']>

<cfset tmp.person2.fname = "Mary">
<cfset tmp.person2.lname = "Doogan">
<cfset tmp.person2.age   = 32>
<cfset tmp.person2.city  = "Kansas City">
<cfset tmp.person2.state = "Missouri">
<cfset tmp.person2.pets  = []>
<cfdump var="#tmp#" format="text">

Produces this output:

Struct
PERSON2 Struct
	AGE number 32 
	LNAME string Doogan 
	PETS Array
	STATE string Missouri 
	CITY string Kansas City 
	FNAME string Mary 

PERSON1 Struct
	AGE number 26 
	LNAME string Smith 
	PETS Array
		1 string Fluffy 
		2 string Mr. Jingles 
		3 string Bambi 
	STATE string Nebraska 
	CITY string Omaha 
	FNAME string John

Railo also supports the “format” attribute, but BlueDragon does not. In fact Railo supports a bunch of interesting attributes to the cfdump tag.

3 Comments

  1. iDayDream says:

    Great, great find. I like to use cfdump in emails and have found that those emails have begun to get quite large due to so much HTML. This will be infinitely better.

  2. Merritt says:

    Thanks for the tip!

  3. Dave says:

    Doing a little debugging search and came across this from one Ryan Stille. Imagine that…