Skip to main content
Ben Nadel
On User Experience (UX) Design, JavaScript, ColdFusion, Node.js, Life, and Love.

Neat Trick With ValueList()

By Ben Nadel on
Tags: ColdFusion

This is just a quick little trick for outputting a list of items with proper spacing. You can use ColdFusion ValueList() using a delimiter that has both a comma AND a space in it: ", ". While this is not really a valid delimiter, which is defined as one character, the ValueList() method will still use both characters when creating the delimited list. Now, you have a nicely spaced list.

<cfquery name="qTags" datasource="...">
		name ASC

<!--- Output nicely formatted tag list. --->
Tags: #ValueList(, ", " )#
Tweet This Deep thoughts by @BenNadel - Neat Trick With ValueList() Woot woot — you rock the party that rocks the body!

Reader Comments

I love CF's list functions. :)

Of course, for the other sort of lists, you can also do this:
<ul><li>#ValueList(, "</li><li>" )#</li></ul>

which has come in handy for me on a couple of occasions.

I'm doing a zip code radius search which I do in another query before pulling my list of companies from my company table. The list of zip codes goes into my search query and are listed in order of distance from the source zip code. So I want the output of the second to be the same order as the value list...

Any ideas?


I'm not quite sure I follow what you mean; but as @Laurence pointed out, a query-of-queries can help you address values on a one-off basis.

What would happen if you wanted to properly html-escape these values in order to prevent cross-site-scripting attacks, or even just display bugs?
(e.g. what if we're talking about algebra, and one of my tags is "a < b > c"? Do you just turn the rest of your website bold?)

Jerry, if you're using Ben's example, you just run HtmlEditFormat (or similar) on the value produced by ValueList.

For my <li>-based example, it would probably be simplest to loop through manually and call HtmlEditFormat on each one (and if you're doing that, you might as well manually build the string instead of using ValueList).

Of course, it would be handy if the ValueList function had the ability to pass a callback function to allow you to process each item before appending it to the list, but unfortunately that's not possible (well, unless you were to write your own ValueList function to do it).

Thanks! Exactly what I was looking for to do a comparison of two data sets and highlight duplicate results contained in the ValueList using a cfif.