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
simply computes a mathematical expression. It uses standard operators, including:  as well as , and brackets   can be used to group operations.

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

{{ #if: |  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
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  evaluates a mathematical expression (like  ) 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 , nothing is output except error messages (such as division by zero). This can be used with  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 because it 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   would output an error message. The  statement would see positive output (not zero/null/whitespace) and so output the. This proves the expression is "invalid".

#switch
The function  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  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
The function  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  to determine whether a path exists:

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

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

This returns  slash-separated segments of , 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.