Switch and When

The Switch and When tags are shortcuts for combining multiple If conditions.

The basic structure is:

<Switch field="field_name">
  <When value="1" />
    Value is 1.
  <When value="2" />
    Value is 2.
  <When />
    Value is something else.
</Switch>

How it works:

  • Both tags can take any attributes of the If tag.
  • The attributes of the Switch tag are combined with those of each When tag.
  • An empty When tag is for matching when none of the previous conditions were true.

The above example should have the same result as:

<If field="field_name" value="1">
  Value is 1.
<Else if field="field_name" value="2" />
  Value is 2.
<Else />
  Value is something else.
</If>