Help:Conditional expressions

This page, Help:Conditional expressions, describes ways to display different results based on checking conditions in a page or template. The parser functions used to evaluate conditional expressions include the function names: #ifexpr, #ifeq, #switch, #if, and #iferror or #ifexist. Each function name has been linked to the explanations below.

  • Using #ifeq can compare 2 strings or numbers.
  • But #ifexpr can check a math formula or multiple conditions.
  • The #switch function can branch to dozens or hundreds of different paths depending on a value, to act as a case statement to choose among alternatives.
  • Using #if can check to see if a parameter has been passed, or if an expression evaluates as true.
  • Using #iferror can check to see if an expression value triggers an error else shows the value.
  • While #ifexist can check to see if a page name or image/media file exists yet.

Note that all extra white space within the outer braces gets stripped out, so this permits formatting these constructs for better readability. For example:

{{#if: {{{xx|}}}
   | parameter xx passed
   | parameter xx omitted
}}

Only the spaces on either side of the xx appear in the text.