5.2 Templates

Revision as of 11:01, 23 July 2024 by Margit Link-Rodrigue (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

What is a template?

A template provides reusable content in the wiki. This content is then integrated into numerous pages. The template can be content-based (text template) or structure-based (layout template), or a combination of both.

A typical example is an infobox that is formatted to look identical on all pages.

A template can also be integrated into a page template.

screenshot of a work instruction
Document control box at the beginning of a document

Characteristics of a template

A template:

  • allows you to insert reusable content with a placeholder (transclusion)
  • is usually located in the "Template" namespace
  • can have parameters
  • often contains logic
  • is used to maintain a "look and feel".

Create and embed a template

A new template is always created in the Template namespace.

A template is inserted into a page by enclosing the name of the template in the source code in two curly brackets: {{NotificationBox}}. Templates are inserted by users via:

Edit a template

Changes to a template affect all pages that contain that template. Before modifying existing templates, you should check which pages use the template. To find these pages, click ...All actions > links to this page in the page actions menu.

Built-in variables

Each MediaWiki has a set of built-in variables that are not pages in the "Template" namespace, but are still used as templates.

For example, the variable {{CURRENTTIME}} returns the current UTC time.

Describe parameters via TemplateData

The MediaWiki extension TemplateData allows template parameters to be described in such a way that they can be easily edited by users in the Visual Editor via a form.

Format template

If a template needs to be specially formatted, e.g. with background color, text spacing or special font formatting, this can be achieved using MediaWiki:Common.css. The formatting can therefore be used multiple times for other templates. If the formatting is specifically limited to this template, it will be created on a subpage of the template using the TemplateStyles tag. The advantage of this is that the style specifications can be easily exported together with the template and imported into another wiki.

Further information

  • Using a template is essentially a transclusion. It is also possible to use pages as templates that are not in the "Template" namespace. However, this should be done carefully as some features require the pages to be in the template namespace.
  • Templates can also be used to define the output of semantic query. For more information, see Semantic MediaWiki. (This is an example where the pages absolutely must be in the template namespace.)
  • The complete list of all wiki pages that are in this namespace can be found on the Special:Templates page.

Related info




To submit feedback about this documentation, visit our community forum.