Help:ParserFunctions

The ParserFunctions extension adds even more parser functions to the magic words allowed on the Scratch Wiki. The syntax of parser functions are:.

#expr
The #expr (expression) function evaluates expressions in the function. The syntax of this function goes:. Expressions are placed in the expression parameter and the function will be replaced with an answer. The expressed answer can be an error message, if the calculation cannot be done. Boolean/logical truth gates considers all numbers except zero to be true, and zero to be false. Empty expressions yield empty answers.

#if
This function evaluates a text field to determine whether it is empty or not. If it is empty, it will print out a value. If not, it will print out another value. The values are user-defined. White space is considered an empty string. All text in the function is parsed as plain text. The syntax of this function goes:.

#ifeq
This function (if equal) evaluates two strings and checks to see if they are equal. The syntax of this function goes:. Avoid putting html tags into the text filed; parser tags are replaced, and will not equal each other. Numerical answer and string answers are parsed differently; numerical values are compared numerically (01 is the same as 1) and string functions are placed in quotations and are case-sensitive and numbers are parsed as text, therefore 01 and 1 are not equal. In this function, all numbers are turned into type integer, so the digit accuracy goes up to 9E18.

#iferror
Functions such as the #expr function, have errors messages in case something goes wrong. This function checks to see if a nested function has outputted an error message or not. The syntax of this function goes:. A combination of parameters are optional. If the 'string if error message is not found' parameter is omitted, then an error-free output will then be displayed. If you remove both 'string if error message is not found' and 'string if error message is found' parameters, then an error will be shown as a blank string.

#ifexpr
This function (if expression [is true/false]) evaluates an expression then returns one of the two parameters. The syntax of this function goes:. The expression is parsed exactly the way #expr is, and a blank expression results in 'false'. In any case, all numbers are equal to true, except zero which is equal to false in boolean calculations. The 'false' parameter can be omitted; if an expression is false, the output shows a blank space. The "true" parameter can also be omitted, but the pipe characters still needs to be placed.

#ifexist
This expensive function takes a string, interprets it as a page title and returns one of two values depending on whether the page exists or not. The syntax of this function goes:. There is a 100 call limit on this function.

#rel2abs
The function turns relative file paths into absolute file paths, as the name suggests ("relative to absolute"). The first parameter is the path, and the second parameter is the base path. The base path is optional - if left nil, the full name of the current page is used. The path parameter accepts the following syntax:


 * the current level
 * go up one level
 * go down one level into the subdirectory x

#switch
This function compares a comparison with several cases, and outputs a string defined in each case. This function is equivalent to: set [comparison v] to [hello] set [output v] to [] if <(comparison) = [hello]> then //case1 set [output v] to [welcome!] else if <(comparison) = [bye]> then //case2 set [output v] to [see you!] else set [output v] to [ok!] //default case end end In this case, the output variable returns "welcome!". Be aware, this function is case-sensitive.

#time
This function formats a given date into a specified format. . The table below gives some of the main format codes that can be used. Careful, the format code is case sensitive.

We can place strings into the format code as well.

#timel
This is exactly the same as #time, but uses the wiki local time taken from $wgLocaltimezone.

#titleparts
The function splits a page title by its slashes and sub-pages. This function can accept three arguments, pagename, optional number of segments, and optional first segment. If the number of segments parameter is omitted, then it defaults to "0", returning all segments. If the first segment parameter is omitted, it defaults to one.