Help:Switch parser

From Ballotpedia
Jump to: navigation, search
Ballotpedia:WikiProject Help

Switch parsers are used to create commands that will post certain information on a wiki page if and only if parameters are specifically filled out. Unlike the IfEq parser, the switch parser allows you to establish multiple inputs with multiple outputs.

Switch parser basics

  • Establish what happens if a certain parameter is defined as a number of specific word or text lines. Similar to #ifeq but provide more options.
  • Useful for choosing to include or not include lines on a table, for changing colors of tables based on party or for changing common combinations of text.
  • Requires a specific input to operate properly.

Switch parser code

The code on the template page reads:
{{#switch: {{{Parameter|}}} | REQUIRED PARAMETER DEFINITION #1 = WHAT WILL RENDER IF DEFINED | REQUIRED PARAMETER DEFINITION #2 = WHAT WILL RENDER IF DEFINED | #default = WHAT WILL RENDER IF DEFINED}}
[1]



The template code example is:
{{#switch: {{{Parameter}}} | Say Hi = Hello World | Say bye = Good bye world | #default = Where is the world?}}



The Template call:
{{Template name|Parameter = Say Hi}} versus {{Template name}} or {{Template name|Parameter = Say bye }} or {{Template name|Parameter = ANYTHING AT ALL }}



The result:
Hello World versus Good bye world or Where is the World?

Advanced switch-parser notes

  • Switch parsers are most useful to alter the appearance of a template based on multiple inputs or to change or shorten the names of standardized page names.
  • Switch parsers can be used to alter information if it is entered with a specific formatting.
  • Switch parsers are case sensitive so please be aware that this can cause an error.

See also

References