Search code examples
coldfusioncoldfusion-9coldfusion-10coldfusion-8

ColdFusion cfcase statements and referencing their variables?


If you have code like so:

<cfcase value="Test">
   /**Do Stuff
</cfcase>

Is it possible to reference that value within the case statement?

I want to concatenate a list that can handle multiple cases and be able to dynamically reference the variables like so:

<cfcase value="Test,Another,Yes,No">
   <cfif this.value EQ 'Test'> blabla </cfif>
</cfcase>

I can't find anything that detailed about this for everywhere I have looked, just curious if it is even possible.


Solution

  • Yes, you can run multiple case statement in a cfcase tag:

    <cfswitch expression="#URL.TestValue#">
    
        <cfcase value="Blue,Red,Orange" delimiters=",">
            <cfoutput>#URL.TestValue#</cfoutput>
        </cfcase>
    
        <cfcase value="Yellow">
            <cfoutput>#URL.TestValue#</cfoutput>
        </cfcase>
    
    </cfswitch>