Jump to content

User:Jim Grisham/Sandbox/Reference/Demos/Rendered variables

From Wikipedia, the free encyclopedia
This is the current revision of this page, as edited by Jonesey95 (talk | contribs) at 20:17, 21 February 2024 (top). The present address (URL) is a permanent link to this version.
(diff) ← Previous revision | Latest revision (diff) | Newer revision → (diff)


References

[edit]


Copied references to sort and format


(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:


From w:Magic:


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 are case sensitive.
  • 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/>}}.

Magic words compared to templates:



Evaluates expression (see m:Help:Calculation).




See also

[edit]


{{collapse top}} {{he:עזרה:משתנים}}

[[he:עזרה:משתנים]]

Examples (live)

[edit]
Section notes

(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)

Page variables:

  • User:Jim Grisham/Sandbox/Reference/Demos/Rendered variables
  • Jim Grisham/Sandbox/Reference/Demos/Rendered variables
  • Jim Grisham/Sandbox/Reference/Demos
  • Jim Grisham
  • Rendered variables
  • User:Jim Grisham/Sandbox/Reference/Demos/Rendered variables
  • User:Jim Grisham/Sandbox/Reference/Demos/Rendered variables
  • User talk:Jim Grisham/Sandbox/Reference/Demos/Rendered variables
  • 2
  • User
  • User
  • User
  • User talk
  • {{SHORTDESC}} (en-wp only)

Page variables (encoded versions):

  • User:Jim_Grisham/Sandbox/Reference/Demos/Rendered_variables
  • Jim_Grisham/Sandbox/Reference/Demos/Rendered_variables
  • Jim_Grisham/Sandbox/Reference/Demos
  • Jim_Grisham
  • Rendered_variables
  • User:Jim_Grisham/Sandbox/Reference/Demos/Rendered_variables
  • User:Jim_Grisham/Sandbox/Reference/Demos/Rendered_variables
  • User_talk:Jim_Grisham/Sandbox/Reference/Demos/Rendered_variables
  • 2
  • User
  • User
  • User
  • User_talk
  • {{SHORTDESC}} (en-wp only)

Site variables:

  • Wikipedia
  • //en.wikipedia.org
  • en.wikipedia.org
  • /w
  • 1.45.0-wmf.4 (146aca8)

Other variables:

Current date and time:

Page revision data:

Wiki statistics:

Parser functions - Metadata:

Transcluded help pages

Help:Magic words - ‘Variables’ section

[edit]
Help:Magic words - ‘Variables’ section
Page name variable Output Description
{{FULLPAGENAME}} User:Jim Grisham/Sandbox/Reference/Demos/Rendered variables Canonical page name. Title line. Title unless letter-case is altered with {{DISPLAYTITLE}}.[a]
{{PAGENAME}} Jim Grisham/Sandbox/Reference/Demos/Rendered variables Title line excluding namespace.
{{BASEPAGENAME}} Jim Grisham/Sandbox/Reference/Demos Title of parent page, excluding namespace.
{{ROOTPAGENAME}} Jim Grisham Title of topmost parent (before all subpages), excluding namespace.
{{SUBPAGENAME}} Rendered variables On a subpage, rightmost portion of current title; higher subpagenames show as backlinks.
{{ARTICLEPAGENAME}} User:Jim Grisham/Sandbox/Reference/Demos/Rendered variables Title of the subject page associated with the current page. These are useful on talk pages (but see note about Category talk pages).
{{SUBJECTPAGENAME}} User:Jim Grisham/Sandbox/Reference/Demos/Rendered variables
{{TALKPAGENAME}} User talk:Jim Grisham/Sandbox/Reference/Demos/Rendered variables Title of the talk page associated with the current page. Useful on subject pages.
{{NAMESPACENUMBER}} 2 Number of the current page's namespace.
{{NAMESPACE}} User Namespace of the title.
{{ARTICLESPACE}} User On a talk page, the namespace part of the title of the associated subject page.
{{SUBJECTSPACE}} User
{{TALKSPACE}} User talk Namespace of the talk page associated with the current page.
{{FULLPAGENAMEE}},
{{PAGENAMEE}},
 (etc.)
User:Jim_Grisham/Sandbox/Reference/Demos/Rendered_variables,
Jim_Grisham/Sandbox/Reference/Demos/Rendered_variables,
(etc.)
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.

information 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}}]].

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

Site variable Output Description
{{SITENAME}} Wikipedia Site name ($wgSitename).
{{SERVER}} //en.wikipedia.org Domain URL ($wgServer).
{{SERVERNAME}} en.wikipedia.org Subdomain and domain name.
{{ARTICLEPATH}} /wiki/$1 Relative article path ($wgArticlePath).
{{SCRIPTPATH}} /w Relative script path ($wgScriptPath).
{{STYLEPATH}} /w/skins Relative style path ($wgStylePath).
{{CURRENTVERSION}} 1.45.0-wmf.4 (146aca8) Returns current MediaWiki version.

Other variables by type

[edit]
Current date and time
Universal time Local-website time
Variable Output Variable Output
{{CURRENTYEAR}} 2025 {{LOCALYEAR}} 2025
{{CURRENTMONTH}} 06 {{LOCALMONTH}} 06
{{CURRENTMONTHNAME}} June {{LOCALMONTHNAME}} June
{{CURRENTMONTHABBREV}} Jun {{LOCALMONTHABBREV}} Jun
{{CURRENTDAY}}[b] 8 {{LOCALDAY}}[b] 8
{{CURRENTDAY2}}[b] 08 {{LOCALDAY2}}[b] 08
{{CURRENTDOW}} 0 {{LOCALDOW}} 0
{{CURRENTDAYNAME}} Sunday {{LOCALDAYNAME}} Sunday
{{CURRENTTIME}} 16:42 {{LOCALTIME}} 16:42
{{CURRENTHOUR}} 16 {{LOCALHOUR}} 16
{{CURRENTWEEK}} 23 {{LOCALWEEK}} 23
{{CURRENTTIMESTAMP}}[c] 20250608164237 {{LOCALTIMESTAMP}}[c] 20250608164237
Page revision data
Variable Output
{{REVISIONDAY}}[b] 21
{{REVISIONDAY2}}[b] 21
{{REVISIONMONTH}} 02
{{REVISIONYEAR}} 2024
{{REVISIONTIMESTAMP}}[c] 20240221201719
{{REVISIONUSER}}[d] Jonesey95
Wiki statistics
{{NUMBEROFPAGES}} 63,298,131
{{NUMBEROFARTICLES}} 7,005,742
{{NUMBEROFFILES}} 937,926
{{NUMBEROFEDITS}} 1,289,831,976
{{NUMBEROFUSERS}} 49,250,412
{{NUMBEROFADMINS}} 839
{{NUMBEROFACTIVEUSERS}} 115,439

Help:Magic words - ‘Parser functions’ section

[edit]
Help:Magic words - ‘Parser functions’ section

Metadata

[edit]
Function Description
{{PAGEID}} Unique page identifier number (for example, this page's ID is 71317940).
{{PAGESIZE:fullpagename}}[e] 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.

Formatting

[edit]
Function Description
{{lc:string}} Converts all characters in string to lower case.
{{lcfirst:string}} Converts first character of string to lower case.
{{uc:string}} Converts all characters in string to upper case.
{{ucfirst:string}} Converts first character of string to upper case.
{{formatnum:unformatted_number}}
{{formatnum:formatted_num |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).
{{#dateformat:date|format}}
{{#formatdate:date|format}}
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.
{{padleft:xyz|stringlength}}
{{padright:xyz|stringlength}}

{{padleft:xyz|length|padstr}}
{{padright:xyz|length|padstr}}
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.
{{plural:N|singular|plural}} Outputs singular if N is equal to 1, otherwise outputs plural. See the documentation at mediawiki.org for more details.
{{#time:format|object}}
{{#timel:format|object}}

{{#time:d F Y|date|langcode}}

{{#timef:object|format type|langcode}}
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.
{{#tag:tagname|content with magic}} 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.

Paths

[edit]
Function Description
{{localurl:fullpagename |query}} 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}} Encodes string 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").
{{anchorencode:string}} Input encoded for use in MediaWiki URL section anchors.
{{ns:n}} Returns the name of the namespace whose index is the number n. For MediaWiki URLs, use {{nse:}}.
{{#rel2abs:path}} Converts a relative file path to an absolute path.
{{#titleparts:fullpagename|number|first segment}} Splits the fullpagename (title) into that number of segments.

Conditional

[edit]
Function Description
{{#expr:expression}} Evaluates expression (see mw:Manual:Expr parser function syntax).
{{#if:string |result1 |result2}} Outputs result2 if string is empty, otherwise outputs result1.
{{#ifeq:string1|string2 |result1 |result2}} Outputs result1 if string1 and string2 are equal (alphabetically or numerically), otherwise outputs result2.
{{#iferror:test_string |result1 |result2}} Outputs result1 if test_string generates a parsing error, otherwise outputs result2.
{{#ifexpr:expression |result1 |result2}} Outputs result1 if expression is true, otherwise outputs result2.
{{#ifexist:pagetitle |result1 |result2}}[e] Outputs result1 if the page [[pagetitle]] exists, otherwise outputs result2. Note that underscores are needed for spaces in namespaces.
{{#switch:string |c1=r1 |c2=r2 ... |default}} 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.).

Other

[edit]
Function Description
{{#babel:code1|code2|...}} Render userboxes telling your language skills. Improves upon {{Babel}} (an alternative).
{{#categorytree:category|...}} List pages in a category, recursively.
{{#coordinates:arg1|arg2|...}} Save the GeoData coordinates of the subject to the page's database. Used in {{coord}}.
{{#invoke:module|function|arg1|...}} Use Scribunto to transclude a lua template, e.g. function replace in module String.
{{#language:code1|code2}} Print the name represented by the language code, e.g. enEnglish. Print in language 2 if given, e.g. {{#language:en|zh}} prints 英语
{{#lst:}}, {{#lsth:}}, {{#lstx:}} Three ways to transclude a section of a page.
{{#mentor:Username}} Display the currently assigned mentor for target Username, if set.
{{#property:arg1|arg2|...}} Include a property (Wikidata) from a named entity, instead of the default on the page.
{{#related:...}} Links to similar topics, to engage readers. (Beta feature.)
{{#section:}}, {{#section-h:}}, {{#section-x:}} Aliases for {{#lst:}}, {{#lsth}}, {{#lstx}} (above).
{{#statements:arg1|...}} Display the value of any statement (Wikidata) included in an item.
{{#target:fullpagename}} Send a message to a list of talk pages on the fullpagename, using the MassMessage function.
{{int:pagename}} Transclude an interface message, i.e. a pagename in MediaWiki namespace
{{!}} 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.

Substituting and nesting

[edit]

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:

Blue question mark? Code Output
Red X symbolN {{PAGESIZE}} 0
Green checkmarkY {{PAGESIZE:Help:Magic words}} 36,447
Green checkmarkY {{subst:PAGESIZE:Help:Magic words}} 36,447
Green checkmarkY {{PAGESIZE:{{FULLPAGENAME}}}} 8,901
Red X symbolN {{subst:PAGESIZE:{{FULLPAGENAME}}}} 0
Green checkmarkY {{PAGESIZE:{{subst:FULLPAGENAME}}}} 36,447
Green checkmarkY {{subst:PAGESIZE:{{subst:FULLPAGENAME}}}} 8,901
[edit]

Subpages: all subpages of this page

Notes

[edit]
Using templates for fun and profit

‘Show variable example’ template

[edit]


Invoking {{User:Jim Grisham/Templates/Show variable example|Namespace}}:

Variant 1

[edit]
Typing
{{User:Jim Grisham/Templates/Show variable example|Namespace}}
... would produce:
Variable {{NAMESPACE}}
User
... by replacing itself with the following HTML and wikitext:
<dt class="variable-name">[[Help:Magic words#Variables|Variable]] ''<nowiki>{{NAMESPACE}}</nowiki>''</dt> <dd class="variable-output">{{NAMESPACE}}</dd>
(Note: this appears to work even without wrapping itself within HTML ‘dictionary list’ tags (i.e. <dl>…</dl>)

Variant 2

[edit]
Typing
{{User:Jim Grisham/Templates/Show variable example|Namespace}}
... would produce:
Variable {{NAMESPACE}}: User
... by replacing itself with the following HTML and wikitext:
<span class="variable-name">[[Help:Magic words#Variables|Variable]] '''<nowiki>{{NAMESPACE}}</nowiki>''':</span> <span class="variable-output">{{NAMESPACE}}</span>

Variant 3

[edit]

(to do: an entire table row, using either Wiki or HTML markup)


Test data

[edit]

Notes on template design

[edit]
  • 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).