Search code examples
listcoldfusioncoldfusion-11

How to add a group of values as a list?


Please assume #headerNames# has the value of Apple Orange Pear.

How do I make this be considered as a list?

I tried this:

<cfset headerList = "">
<cfset headerList = ListAppend(headerList,"#headerNames#",",")>

But this doesn't work. So how do I store the values of #headerNames#as a list?

PS: the reason why I asked to assume #headerNames# is because the values come from reading an excel file, thus, a lot of unrelated codes to this question. But if those are needed, please let me know and I will edit / update the question.


Solution

  • You don't actually have to change anything for this to be considered a list. ColdFusion recognizes a space as a valid delimiter:

    <cfset headerNames = "Apple Orange Pear">
    
    <cfoutput>
        <cfloop list="#headerNames#" delimiters=" " index="i">
            #i#<br />
        </cfloop>
    </cfoutput>
    
    <!--- output:
    Apple
    Orange
    Pear
    --->