5.2 Templates

(Created page with "<bookshelf src="Book:User manual" />")
 
No edit summary
 
(2 intermediate revisions by the same user not shown)
Line 1: Line 1:
<bookshelf src="Book:User manual" />
<bookshelf src="Book:User manual" />
==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 [[Manual:Extension/BlueSpicePageTemplates|page template]].
[[File:Template IMS Work instruction.png|alt=screenshot of a work instruction|center|thumb|650x650px|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 <code>Template</code> namespace.
A template is inserted into a page by enclosing the name of the template in the source code in two curly brackets: <code><nowiki>{{NotificationBox}}</nowiki>.</code> Templates are inserted by users via:
* the Insert menu item of the [[Manual:Extension/VisualEditor|editor toolbar]]
* as a [[Manual:Extension/ContentDroplets|Content droplet]]
==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 <code>...All actions > links to this page</code> in the page actions menu.
==Built-in variables==
Each MediaWiki has a set of [[Manual:Extension/BlueSpiceInsertMagic|built-in variables]] that are not pages in the "Template" namespace, but are still used as templates.
For example, the variable <tt><nowiki>{{CURRENTTIME}}</nowiki></tt> returns the current UTC time.
==Describe parameters via TemplateData==
The MediaWiki extension [[mediawikiwiki:Help:TemplateData#Template_data_editor_method|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 [[mediawikiwiki:Extension:TemplateStyles|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 [[mediawikiwiki:Transclusion|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 [https://www.semantic-mediawiki.org/wiki/Help:embedded_query semantic query]. For more information, see [https://www.semantic-mediawiki.org/wiki/Help:Template_format 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 <code>Special:Templates</code> page.
{{Box_Links-en| Topic1 = https://www.mediawiki.org/wiki/Help:Templates| Topic2 = https://www.mediawiki.org/wiki/Help:Extension:ParserFunctions| Topic 3=  | Topic4 = }}
[[de:Handbuch:Vorlagen]]
[[Category:Content]]
[[Category:Organization]]

Latest revision as of 11:01, 23 July 2024

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.