No categories assigned

Magic words

Revision as of 15:58, 25 October 2019 by Mlink-rodrigue (talk | contribs)


What are magic words?

A "magic word", also known as MagicWord, 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.

Types of magic words

Behavior switch

Characteristics of behavior switches:

  • Purpose: controls the layout or behavior of the page (if supported by the skin)
  • Syntax: __NOTOC__

Description:

A behavior switch includes or omits certain elements of the page. It is also known as "double underscore". Behavior switches can be put anywhere in the source code of the designated page (usually at the end of the page). The behavior switch __TOC__ produces as output the table of contents exactly where it was inserted on the page.====

Variable

Characteristics of variables:

  • Purpose: returns information about the page, wiki, or date
  • Syntax: {{PAGENAME}}

Description:

Variables contain (simple) dynamic data. If a template name conflicts with a variable, the variable is used. For example, you have the variable {{PAGENAME}}. In that case, you have to transclude the template with the same name as {{Template:PAGENAME}}.

Parser Function

Characteristics of parser functions:
  • Purpose: function as a simple "programming language for page content and are found mainly in templates
  • Syntax: {{#if:{{{field|}}} | {{{field|}}} | N/A }}
Description:

Parser functions are similar to variables, but take one or more parameters.Example:

{{#ifeq:{{{type}}}|warning
|This is a warning!
|
}}

They are used for simple logic only, since they are hard to read and to maintain on a larger scale. If complex logic is required, consider Lua scripts in the "Module" namespace (Extension:Scribunto) and invoke using {{#invoke:...}}

Parser functions can also be "tag-like", e.g. {{#ask:...}} from SemanticMediaWiki. For more information, refer to the MediaWiki help pages Help:Extension:ParserFunctions and Help:Magic_words#Parser_functions.

Tag

Characteristics of tags:

  • Purpose: often used for custom development to process dynamic content
  • Syntax: <smartlist />

Description:

Tags are implemented in PHP as part of a MediaWiki extension. Tags with "bs:" prefix come from BlueSpice (see Reference:BlueSpiceTagSearch). All others come from MediaWiki or from third-party extensions, e.g. the extension SyntaxHighlight.

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 info

Attachments

Discussions