-1

Can I use another cfswitch statement within the same cfswitch case?

<CFSWITCH EXPRESSION="nameOfPg">
  <CFCASE VALUE="ClassMenu" >
    <!---do something--->
  </CFCASE>
  <CFCASE VALUE="ReportsMenu">
    <CFSWITCH EXPRESSION="#nameOfPg#">
      <CFCASE VALUE="StudentMenu">
        <!---do something--->
      </CFCASE>
      <CFCASE VALUE="DetailsMenu">
        <!---do something--->
      </CFCASE>
    </CFSWITCH>
  </CFCASE>
  <CFDEFAULTCASE>
    <!---do something--->
  </CFDEFAULTCASE>
</CFSWITCH>
ale
  • 6,369
  • 7
  • 55
  • 65
kiara
  • 23
  • 6
  • Hello and welcome to StackOverflow. Please take some time to read the help page, especially the sections named ["What topics can I ask about here?"](http://stackoverflow.com/help/on-topic) and ["What types of questions should I avoid asking?"](http://stackoverflow.com/help/dont-ask). And more importantly, please read [the Stack Overflow question checklist](http://meta.stackexchange.com/q/156810/204922). You might also want to learn about [Minimal, Complete, and Verifiable Examples](http://stackoverflow.com/help/mcve). – Ataur Rahman Munna Oct 31 '16 at 06:55
  • 5
    Why not simply just try? Worst case you'll get an error and it'll tell you you can't do it. – ale Oct 31 '16 at 13:39

1 Answers1

0

Yes, you can. The EXPRESSION attribute can be dynamic (e.g. a variable such as nameOfPg), but pay attention to the hashes #.

nameOfPg (your top CFSWITCH) evaluates the string, not the actual value of the variable nameOfPg. To resolve a variable in an attribute, you need to use hashes # like you did in your inner CFSWITCH: #nameOfPg#.

Fix your code:

<CFSWITCH EXPRESSION="#nameOfPg#">
  <CFCASE VALUE="ClassMenu" >
    <!---do something--->

and you should be good.

On a side note: CFCASE on the other hand does not allow the use of dynamic values (due to to the way a switch works in Java/ColdFusion). You always have to use a static value here like you do right now. Just keep that in mind.

Alex
  • 7,743
  • 1
  • 18
  • 38
  • wow, I see now. I was missing the hashes. Thanks for the help. The example code I used same EXPRESSION (eg. #nameOfPg#), but I want to know, Can I use different EXPRESSION into both cfswitches? – kiara Nov 01 '16 at 01:40
  • Yes, they can be different. – Alex Nov 01 '16 at 12:12