To avoid nested if statements and improve readability, I wanted to create switch(true){ ... } in Coldfusion. I often used this in php, but when I try this in Coldfusion, I get the following error on initialization:
Template Error
This expression must have a constant meaning.
This happens when a variable in its state is used in the case of a switch, for example:
//this example throws the error switch(true){ case foo == 1: writeOutput('foo is 1'); break; }
Using the switch (true) {...} operator with constant values (as the error explains) works:
//this example doesn't throw the error switch(true){ case 1 == 1: writeOutput('1 is 1'); break; }
Is there a way to get the first statement to work in Coldfusion? Maybe with evaluating a variable or some tricks, or is it definitely not going to Coldfusion?
source share