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.
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>
Well... yeah... if your <cfswitch>
expression was #originalExpression#
, then the value that caused the case to trigger will be... #originalExpression#
. There's no need to be tricky about it!
IE: you'll need to do something like this:
<cfswitch expression="#originalExpression#">
<cfcase value="Test,Another,Yes,No">
<!--- stuff common to all of Test,Another,Yes,No ---->
<!--- stuff specific to various cases --->
<cfif originalExpression EQ "test">
<!--- do stuff ---->
<cfelseif listFindNoCase("Yes,No", originalExpression)>
<!--- do stuff ---->
<cfelse>
<!--- do stuff for "another" --->
</cfif>
</cfcase>
<!--- other cases etc --->
</cfswitch>
I don't think it is possible using ColdFusion tags. You can do something similar with <cfscript>
switch (expression) {
case "Test" :
// Do some extra stuff
// No break here
case "Another" : case "Yes" : case "No" :
// Do yet some normal stuff
break;
}
Disclaimer: I would not want to maintain this code
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With