Help:Parser Functions

Parser Functions are extensions to the MediaWiki software, mainly allowing IF statements.


 * Read more at http://meta.wikimedia.org/wiki/ParserFunctions

#expr
Expr simply computes a mathematical expression. It uses standard operators, including:  as well as , and brackets   can be used to group operations.

#if
The If statement shows something if the condition evaluates to anything other than zero, with the option of displaying alternative text.

Putting anything in the will output the section. If the is empty, null zero or white space, the section will output (if it exists). If the section is not included, and the is null/zero/whitespace nothing will output.

#ifexist
Ifexist returns one of two results based on whether or not a particular page exists.

Standard naming convention applies: the page Vehicles is accessible from Vehicles or vehicles, but not VEHICLES. Interwiki links and special pages will output as.

#ifexpr
The function #ifexpr evaluates a mathematical expression (like #expr) and returns one of two strings depending on the result.

For example, outputs yes.

if expression is valid
If both the and are missing from #ifexpr, nothing is output except error messages (such as division by zero). This can be use with #if to determine if an expression is valid, rather than attempting to output the result:

The above expression is "valid". The condition will not output any error is a valid equation, so the output will be blank (as opposed to an error message). The if statement sees no output, so reports the statement, which proves the expression is "valid".

If the expression was invalid (such as ), then the #ifexpr would output an error message. The if statement would see positive output (not zero/null/whitespace) and so output the. This proves the expression is "invalid".

#switch
The function #switch compares a single value against multiple others, returning a string if a match is found.

If is, then will output. If it is, then will output. If it is none of these, then will output.

It is possible to have a fall-through, allowing multiple to have one entry:

If is or or, then  will output.

String comparison is case-sensitive. To be made case-insensitive, use the Magic Word to force everything to lowercase (or  for upper case):

gives UPPER gives lower

#time
The function #time outputs the time, using a format string similar to that of PHP Date:

For example:

gives "Sunday 4 March 2007" gives "Sunday 6 April 2008" (32 days ago) gives "20:17" (6 hours later than UTC)

#rel2abs
rel2abs converts a relative path to an absolute path:


 * If standing in Help:Foo/bar and is calling, the result will be Help:Foo/baz
 * If standing in Help:Foo and is calling, the result will be baz

If you try to go up too many levels (an invalid relative path) an error will be output.

if relative path exists
This can be used in combination with #ifexist to determine whether a path exists:

gives '..' does not exist gives '.' exist

#titleparts
Titleparts returns a number of slash-separated segments of given a page name, starting from a specified segment.

This returns num slash-separated segments of pagename, starting from the specified starting segment.

"" gives "Help:Link/a/b" "" gives "Help:Link/a" "" gives "a/b" "" gives "b" "" gives b

Table Syntax
Currently wiki pipe table syntax doesn't work inside conditionals, but this can be worked around by using |  to replace using | for the table syntax.