Parser functions are a very useful set of wikitext functions that operate similar to magic words and for the most part includes the previously separate string functions (since 2009). These functions are included in part as built-in MediaWiki engine functionality, but largely from the ParserFunctions extension. Parser functions primarily include logical functions like {{#if:...}}, {{#ifeq:...}}, and {{#switch:...}}, but also includes a few utility functions like {{#time:...}} and {{#titleparts:...}}.

Step-by-step use

  1. Identify the parser function that is appropriate for the task you are trying to do. There are a wide variety of parser functions, so be sure to do your research.
  2. Identify the proper syntax for the parser function you wish to use.
    In this step-by-step guide, we will be using the {{#ifexpr:}} (if expression) parser function, its syntax is: {{#ifexpr: expression | value if true | value if false }}
  3. Fill in the syntax.
    {{#ifexpr: 1 > 0 | yes | no }}
    In the example above, we filled in the mathematical expression (1 > 0), set the function to say "yes" if 1 > 0 is mathematically correct and say "no" if 1 > 0 is mathematically incorrect.
  4. Save the page and verify that the function seems to be returning the expected value. In our example, "yes" should be returned because 1 is indeed greater than 0. 
    {{#ifexpr: 1 > 0 | yes | no }} → yes.
    Note what would have happened if we had tweaked the expression but kept the returned values the same. The equation proves false because 0 is not greater than 1 and "no" is returned.
    {{#ifexpr: 1 < 0 | yes | no }} → no.

While the above example might seem different, because one should always know 1 > 0, the performance and power of the parser function is revealed when it is passed a parameter. Let's say you are designing an infobox for a wiki about a TV show. You want to include a character's age and determine if they are an adult or not.

If within the infobox you have {{#ifexpr: {{{Age}}} >= 18 | This character is an adult. | This character is not an adult. }}, the code would say "This character is an adult" if the given age of the character is at or above 18. If the given age was less than 18, the code would instead say "this character is not an adult."

ParserFunctions Extension

The ParserFunctions extension is a popular MediaWiki extension that adds numerous useful parser functions on a wiki. This extension is enabled by default across all of FANDOM and includes most of the functions found in the now deprecated extension StringFunctions.

What can parser functions do?

ParserFunctions extension has functions for mathematical operations, if/else statements, and time functions. To view a complete list of these functions, go to extension's official help page.

See also

External links

Note: This is a generic section stub. Expand it by clicking Sprite-monaco-pencil Edit to right of the section title.

Start a Discussion Discussions about Parser function