Jump to content

Help:ParserFunctions

From Wikipedia

ParserFunctions are features of MediaWiki that allow editors to perform conditional logic, mathematical expressions, string handling, and time/date formatting within wikitext. They are implemented as magic words beginning with a hash mark (e.g., ), and are provided by the ParserFunctions extension and the core parser.

Syntax overview

[edit]
  • General form: {{#functionname: param1 | param2 | ... }}
  • Pipes (|) separate parameters.
  • Nested functions are allowed; parse from the innermost to outermost.
  • Whitespace around pipes is usually ignored, but avoid trailing spaces in titles or file names.

Core functions

[edit]
{{[[Template:#if|#if]]}} – conditional presence
then
Renders then if test is non-empty; otherwise renders else.
Example: No parameter
{{[[Template:#ifeq|#ifeq]]}} – equality test
not equal
Compares normalized strings (case-sensitive by default).
{{[[Template:#iferror|#iferror]]}} – catch parser errors
ok
True if expression produces a parser error (e.g., division by zero).
{{[[Template:#ifexpr|#ifexpr]]}} – numeric condition
Expression error: Unrecognized punctuation character "'".
Evaluates arithmetic/boolean expressions (see #expr).
{{[[Template:#switch|#switch]]}} – multi-branch selection
outputD
First matching case wins; use #default for fallback.
{{[[Template:#time|#time]]}} – format dates and times
Error: Invalid time.
Example: 2026-04-10 → outputs current date.
{{[[Template:#expr|#expr]]}} – arithmetic and comparisons
Expression error: Unrecognized punctuation character "'".
Supports + - * / ^ parentheses, comparisons (= < > <= >= <>), logical and or not, and functions like round, floor, ceil, mod.
Example: 20 → 20
{{[[Template:#language|#language]]}} – language names
code → language name for ISO code (e.g., 日本語 → Japanese).

String functions (from Scribunto or templates)

[edit]

MediaWiki core has limited string handling. Many projects use Scribunto (Lua) or helper templates to emulate:

  • text / TEXT – lowercase/uppercase
  • Text / text – change first letter case
  • value, ...
  • Template:Len: text – length (often via template)

Check local documentation for which helpers are installed.

Nesting and precedence

[edit]
  • Nest ParserFunctions to build complex logic: yes
  • Use parentheses in #expr to control order: 9
  • Strip markers may appear with heavy nesting; preview to ensure expected output.

Examples

[edit]
Conditional content
Welcome, Guest!
Switch-based messages
Status unknown
Dates
Fri, 10 Apr 2026 17:13:06 +0000RFC 2822 datetime
January 31, 2024 → January 31, 2024
Math
81 → 81
correct
Localization
中文 → Chinese

Common pitfalls

[edit]
  • Use |- to separate table rows (not |--).
  • #expr is plain text; it does not render TeX. To typeset math, use .
  • Avoid trailing spaces in parameters; they can affect equality tests.
  • Division by zero triggers errors; catch with #iferror.
  • Excessive nesting may cause strip-marker artifacts; simplify or split logic.

Performance notes

[edit]
  • Complex ParserFunctions increase parse time; prefer templates or Lua for heavy logic.
  • Caching: Output that varies by time or variables may reduce cache hits.

See also

[edit]