Edit source Discussion

Help:Magic words

From Appropedia

Magic words are strings of text that MediaWiki associates with a return value or function, such as time, site details, or page names.

For full details, see mw:Help:Magic words.

Examples[edit source]

  • __NOTOC__ - Hides the table of contents (short for "NO Table Of Contents").
  • __NOINDEX__ - Tell search engines not to index the page
  • {{CURRENTYEAR}} - Current year: 2021
  • {{NUMBEROFARTICLES}} - Number of pages in content namespaces: 9,169
  • {{FULLPAGENAME}} - Namespace and page title: Help:Magic words
  • {{PAGENAME}} - Page title: Magic words

There are many, many more, for a wide range of date and time, site statistics and page name data.

Parser functions[edit source]

This page describes the parser functions that can be entered in Wikicode to process more complex functions and calculations to be performed. They are especially useful in creating templates.

Some are provided by the MediaWiki ParserFunctions extension and have syntax:

{{#functionname: argument 1 | argument 2 | argument 3 ...}}

Others are basic MediaWiki functions and generally have syntax:

 {{Functionname: argument 1 | argument 2 | argument 3 ...}} 

Extra parser functions[edit source]

The Parser Functions extension is enabled on Appropedia, giving another 11 functions, including if and switch functions, to perform certain logical operations. Examples include:

  • #expr evaluates an expression as true (1) or false (0). For logical inputs, any non-zero number is true, and 0 is false
    • {{#expr: 1.5*2=3 }} → 1
    • {{#expr: 1.5*2=400 }} → 0
    • {{#expr: 1 and 0 }} → 0
    • {{#expr: 1 or 0 }} → 1
  • #if is a little counterintuitive. It returns a true value if the first parameter is 'non-empty'. If it is empty or only whitespace, it evaluates to false. A mathematical expression is treated as a string and evaluates to true even if the expression itself is false. The second parameter is the 'true' output, and the third and final parameter is the 'false' output:
    • {{#if: blah | rhino | unicorn }} → rhino
    • {{#if: | rhino | unicorn }} → unicorn
    • {{#if: 0 | yes | no }} → yes
  • #ifexpr evaluates a mathematical expression and returns the second parameter string if true, and the third (and last) parameter string if false. E.g.:
    • {{#ifexpr: 1 < 0 | true | false}} → false
    • {{#ifexpr: 1+1=2 | blue | red}} → blue
    1. switch displays the value of one of its parameters, e.g. {{#switch: baz | foo = Foo | baz = Baz | Bar }}
    2. fullurl outputs a page's URL, e.g. {{Fullurl:page name}} {{Fullurl:passive solar}}https://www.appropedia.org/Passive_solar

For full details, see mw:Help:Magic words #Parser functions. For more detailed information, visit wiki/Help:Parser_function

Recommendations[edit source]

  • Use in templates, not directly in pages.
  • If you're experimenting with parser function code, especially complex code, use your userspace. E.g. put the template at [[User:Yourname/templatename]], and insert the template using {{User:Yourname/templatename}}. If it proves useful, it can be moved to template space later.
  • If your documentation explains how your template works, this helps future editors of the template.

Further reading[edit source]

You can check a full list on mw:Help:Magic words