stringtranslate.com

Help:Magic words

Magic words (including parser functions, variables and behavior switches) are features of wiki markup that give instructions to Wikipedia's underlying MediaWiki software. For example, magic words can suppress or position the table of contents, disable indexing by external search engines, and produce output dynamically based on the current page or on user-defined conditional logic. Some of these features are especially useful for templates.

This page is a quick reference for magic words. For more information, refer to the main MediaWiki documentation:

General information

In general, there are three types of magic words.

  1. Behavior switches: often appear in double underscores, all uppercase, e.g., __NOTOC__. They will change the behavior of a page, rather than return a value.
  2. Parser functions: all in lowercase. A parser function will be followed by colon and pipe-separated parameters, e.g., {{#ifexpr:Y|Yes|No}}, wrapped in double braces. They will take a value and return a value.
  3. Variables: these are all uppercase, e.g., {{PAGENAME}}. A variable will be wrapped in double braces and will return a value in its place.

The software generally interprets magic words in the following way:

Magic words compared to templates:

Most magic words can be used in any needed locations on a page; see MOS:ORDER for guidance on where to place magic words that are behavior switches.

Behavior switches

Variables

  • WP:VAR

Note: The magic words above can also take a parameter, in order to parse values on a page other than the current page. A colon (:) is used to pass the parameter, rather than a pipe (|) that is used in templates, like {{MAGICWORD:value}}. For example, {{TALKPAGENAME:Wikipedia:MOS}} returns Wikipedia talk:MOS on any page.

Note: In the "Category" and "Category talk" namespaces, to wikilink (some) page name variables may require prefixing a colon to avoid unwanted categorization.

For more details on parser functions that relate to page names and namespaces, see: meta:Help:Page name § Variables and parser functions.

Other variables by type

Parser functions

  • WP:PF
  • WP:PARSER

Metadata

Page IDs can be associated with articles via wikilinks (i.e. Special:Redirect/page/3235121goes to this page). To output numbers without comma separators (for example, as "123456789" rather than "123,456,789"), append the parameter |R.

Formatting

Paths

Conditional

If, in these conditional functions, empty unnamed parameters are to be parsed as empty rather than as text (i.e. as empty rather than as the text "{{{1}}}", "{{{2}}}", etc.), they will require trailing pipes (i.e. {{{1|}}}, {{{2|}}}, etc., rather than {{{1}}}, {{{2}}}, etc.).

Other

Substituting and nesting

Magic words can sometimes behave weirdly when substituted or nested. It's possible to subst some magic words (so that the page stops being updated if the value of the word changes). Here are some examples of how this works:

See also

Notes

  1. ^ If {{FULLPAGENAME}} is used in a page that is transcluded from another page, it will return the name of the target. {{#invoke:TEMPLATENAME|main}} can be used to determine the name of the template itself.
  2. ^ a b c d e f {{CURRENTDAY}}, {{LOCALDAY}} and {{REVISIONDAY}} return the day (e.g. "6"), whilst {{CURRENTDAY2}}, {{LOCALDAY2}} and {{REVISIONDAY2}} return the day with zero-padding (e.g. "06"). For all two-digit days (i.e. 10 to 31), these are the same.
  3. ^ a b c These timestamp outputs can be formatted with {{Format revisiontimestamp}} (aka {{FRTS}}). For example, {{FRTS|{{REVISIONTIMESTAMP}}}} turns "20240811093711" into "2024-08-11 09:37:11".
  4. ^ This shows the last user to edit the page. There is no way to show the user viewing the page with magic words due to technical restrictions.
  5. ^ a b This function is an expensive parser function.