(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:
mw:Help:Magic words: All standard magic words, including the "standard" parser functions.
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.
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.
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:
White space is generously allowed for readability. It will be stripped from the start and end of their keywords and parameters (as is also done inside templates).
They can be transcluded, even variables "about the current page". This is ensured by the parsing order.
Instead of magically transforming into HTML instructions, <nowiki> tags remove this magic so a magic word can itself be displayed (documented), e.g. <nowiki>{{#magic:}}</nowiki>or {{#magic:<nowiki/>}}.
(note: add labels for each, or create a template to do that automatically)
(note: allow ‘transcluding’ this section into other pages for (temporary) troubleshooting purposes?)
(note: these ‘magic word variables’ can be given a different page name as a parameter, but they use a colon (:) instead of the pipe (|) character used with regular MediaWiki templates)
Adding an E to the end of the above variables, renders the above encoded for use in MediaWiki URLs (i.e. with underscores replacing spaces).
{{SHORTDESC}}
Only works on the English Wikipedia, where it displays a short description below the article title on mobile platforms. See Wikipedia:Short description.
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.
Caution: Attempting to use (some) page name variables to create a wikilink to an image page, category page or interlanguage link will produce a different effect: this will respectively place the image on the page, add the page to the category, or create an interlanguage link at the edge of the page. To override this normal behavior, prefix the variable with a colon (:); for example [[:{{FULLPAGENAME}}]].
Size of named page in bytes (for example, this page is 8,901 bytes).
{{PROTECTIONLEVEL:action|fullpagename}}
Protection level assigned to action ("edit", "move", etc.) on named page (this page's protection level for "edit" is autoconfirmed).
{{PROTECTIONEXPIRY:action|fullpagename}}
Protection expiry assigned to action ("edit", "move", etc.) on named page (this page's protection expiry is infinity).
{{PENDINGCHANGELEVEL:fullpagename}}
Protection level for pending changes on the named page (this page, which doesn't have one, is).
{{PAGESINCATEGORY:categoryname}}
Number of pages in the category named categoryname. Each subcategory is counted as one item.
{{NUMBERINGROUP:groupname}}
Number of users in the user group named groupname.
Page IDs can be associated with articles via wikilinks (i.e. Special:Redirect/page/3235121 goes to this page).
To output numbers without comma separators (for example, as "123456789" rather than "123,456,789"), append the parameter |R.
Adds comma separators to an unformatted_number (e.g. 123456789 becomes 123,456,789). To remove such formatting, use {{formatnum:formatted_number|R}} (i.e. 7,654,321|R, for example, produces 7654321).
Formats a date according to user preferences; a default can be given as an optional case-sensitive second parameter for users without date preference; can convert a date from an existing format to any of dmy, mdy, ymd, or ISO 8601 formats, with the user's preference overriding the specified format.
Pad with zeroes '0' to the right or left, to fill the given length; an alternative padding string can be given as a third parameter; the repeated padding string (padstr) will be truncated if its length does not evenly divide the required number of characters.
Used to format dates and times, for ISO format, dots or English month names. #timel and #timefl are based on local time as defined for each wiki; for English Wikipedia, this is identical to #time and #timef. The optional 3rd parameter is the output language code (French, German, Swedish: fr, de, sv, etc.). Example Finnish: {{#time:d F Y|June 30, 2016|fi}} shows: 30 kesäkuu 2016 (June). ISO to German: {{#time:d. M Y|1987-10-31|de}} shows: 31. Okt. 1987. For format codes, see: mw:Help:Extension:ParserFunctions##time. Use the format {{#time: H:i, j F Y (e)|...}} to match the format used by timestamps in signatures. #timef formats a date using a standard format for the selected language, see: mw:Help:Extension:ParserFunctions##timef.
{{gender:user|m_out|f_out|u_out}}
Outputs m_out, f_out or u_out according to whether the gender specified in user's preferences is, respectively, male, female or unspecified. Other parameter permutations are available, see mw:Help:Magic words#gender and translatewiki:Gender.
Only way to evaluate magic words inside a tag, in order to generate <tagname>magic</tagname>. Also handles tag attributes. Details at mw:Help:Magic words#tag.
Relative path to page name. The query parameter is optional.
{{fullurl:fullpagename |query}}
Absolute path, without protocol prefix (i.e. without "http:" etc.), to page name. The query parameter is optional.
{{canonicalurl:fullpagename |query}}
Absolute path, including protocol prefix, to page name. The query parameter is optional.
{{filepath:filename}}
Absolute path to the media file filename.
{{urlencode:string}}
Encodesstring for use in URL query strings; test+string, for example, produces: test+string. To encode string for use in URL paths or MediaWiki page names, append, respectively, |PATH or |WIKI (to produce "test%20string" or "test_string").
Outputs r1 if string is c1, r2 if string is c2, etc., otherwise outputs default (if provided).
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 "Parser functions", "{{{2}}}", etc.), they will require trailing pipes (i.e. {{{1|}}}, {{{2|}}}, etc., rather than Parser functions, {{{2}}}, etc.).
Used to include a pipe character as part of a template argument or table cell contents. Before this was added as a magic word, many wikis implemented this by creating Template:! with | as the content.
Used to include an equal sign as part of a template argument or table cell contents. Before this was added as a magic word, many wikis implemented this by creating Template:= with = as the content.
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:
Could I use another template to automate the creation of documentation itself (instead of typing it manually as I did for the variants above? (July 2022-jhg)
Cite error: There are <ref group=lower-alpha> tags or {{efn}} templates on this page, but the references will not show without a {{reflist|group=lower-alpha}} template or {{notelist}} template (see the help page).