Template
-
- Last edited 4 years ago by MLR
-
-
- This page is approved but has a draft version
Contents
What is a template?
A template is a type of reusable content that can be integrated into other pages of the wiki. It can be content-based (text template) or structure-based (layout template) or a combination of both.
A simple example is a notification box that looks identical on all pages, but contains different content on each page where it is used (layout template).
A template can also be used as the source for a page template.
Characteristics of a template
- allows inserting reusable content with a placeholder
- is usually located in the namespace "Template"
- can have parameters
- often contains logic
- used to maintain a "look and feel"
[
Creating and including a template
A new template is created like a regular page, but in the namespace Template.
A template is then included in a page by putting the name of the template (i.e., the title of the template page without the namespace prefix "Template:") in two curly brackets:{{NotificationBox}}
Note: Template names are case-sensitive.
Editing a template
Changes to a template affect all pages that include this template. Before existing templates are changed, it is recommended that you check which pages use the template. To find these pages, you can go to Page tools > Toolbox > What links here
.
Built-in variables
Each MediaWiki has a number 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 the current UTC time.
Further notes
- The use of a template is basically a transclusion. It is also possible to use pages as templates that are not in the Template namespace. However, this is to be done wisely, since some functions require that the pages are in the template namespace.
- Templates can also be used to define the output of semantic query. For more information, go to Semantic MediaWiki. (This is an example where the pages must necessarily be in the template namespace.)
- The complete list of all pages of the wiki that are located in this namespace can be found on the page
Special:Templates
.