Switch Context

[Switch Value]Series of [Case]...[/Case] contexts[/Switch]

New in 4.0
Executes the WebDNA inside the only [Case] context which matches the given value.

To display some HTML (or execute some WebDNA) from a list of known text options, put the text value inside a [Switch] context. For each possible option, put a [Case] context inside the [Switch]. You may optionally specify a default case by inserting a [Default] context. The [Default] context must be the very last context inside the [Switch].

Example (normally you would put the following text into a .tpl file on your server and use a web browser to link to it):

[text]x=5[/text]
[Switch value=[x]]
  [Case value=1]
    The value of x was 1
  [/Case]
  [Case value=2]
    The value of x was 2
  [/Case]
  [Default]
    The value of x was neither 1 nor 2; it was [x]
  [/Default]
[/Switch]

[text]title=Mrs[/text]
[Switch value=[title]]
  [Case value=Mr]
    You're a male
  [/Case]
  [Case value=Mrs]
    You're a female
  [/Case]
[/Switch]

In the first example above, the text "The value of x was neither 1 nor 2; it was 5" will display, because the two cases for "1" and "2" did not match the actual value of x, which was "5." In the second example above, the text "You're a female" will display. Any WebDNA inside the other [Case] contexts will not execut, and any text inside those contexts will not display.

Note: The values are compared as case-insensitive text only. This means the number "1.0" is not the same as the number "1" when determining which of the [Case] contexts to execute.

User Contributed Notes
SwitchContext  

Copyright © 2008 WebDNA Software Corporation, Inc.