No categories assigned

MagicWords

Revision as of 09:07, 14 October 2019 by Mlink-rodrigue (talk | contribs)


What are magic words?

A "magic word" is a symbol recognized by the MediaWiki software. It triggers the software to do something other than display that symbol, or transclude a page with that name, but instead to use the symbol directly.

There are four types of magic words:

Type of magic word Syntax Example magic word Example output
variable {{FOO}} {{FULLPAGENAME}} Training:EN/MagicWords
  • returns information about the page, wiki, or date
  • is mainly used within templates
tag <foo> <tagsearch cat="Training">
  • implemented in PHP as part of a MediaWiki extension
  • tags with "bs:" prefix com from BlueSpice. See Reference:TagSearch
  • all others come form MediaWiki or from third-party extensions, e.g. Extension:SyntaxHighlight
behavior switch __FOO__ __NOTOC__ hides the table of contents (TOC)
  • controls the layout or behavior of the page (if supported by the skin)
  • includes or omits certain elements of the page
  • also known as "double underscore"
  • can be put anywhere in the source code of the designated page (usually at the end of the page), with exception of __TOC__ (output of the table of contents is where the behavior switch is inserted
parser function {{foo:...}}

or {{#foo:...}}

{{#dateformat:date|ISO 8601}} 2019-12-31
{{{#userslink:(who?)} shows all users who are online
{{#hwinfobox:}} shows five latest changes with the dates
  • similar to a variable, but takes one or more parameters.
  • used to program simple logic into pages (templates).
    • Only for simple logic! Be aware: hard to read / maintain if in larger scale!
    • If complex logic is required, consider Lua script in "Module" namespace (Extension:Scribunto) and invoke using {{#invoke:...}}
  • can also be "tag-like", e.g. {{#ask:...}} from SemanticMediaWiki
  • see Help:Extension:ParserFunctions and Help:Magic_words#Parser_functions
{{#ifeq:{{{type}}}|warning
|This is a warning!
|
}}

How to add a magic word

Magic words are inserted directly in the source code. Some frequently used magic words can also be added directly with the VisualEditor "Insert > Magic word" menu item:

Manual:VE-insert-magicword.png

Related information

Attachments

Discussions