5.2 Templates

No edit summary
Tag: 2017 source edit
No edit summary
Line 5: Line 5:


A typical example is an infobox that is formatted to look identical on all pages.
A typical example is an infobox that is formatted to look identical on all pages.
[[File:Manual:template.png|alternative text=Example of an infobox template|centered|mini|750x750px|Example of an infobox template]]


A template can also be integrated into a [[Manual:Extension/BlueSpicePageTemplates|page template]].
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==
==Characteristics of a template==
Features of a template:<!-- Transferred to training materials! -->
A template:
<section begin="training" />
*allows you to insert reusable content with a placeholder (transclusion)
*[[File:Manual:template-example.png|alternative text=Source text view of an integrated template|mini|400x400px|Source text view of an integrated template]]allows you to insert reusable content with a placeholder (transclusion)
*is usually located in the "Template" namespace
*usually located in the "Template" namespace
*can have parameters
*can have parameters
*often contains logic
*often contains logic
*used to maintain a "look and feel".
*is used to maintain a "look and feel".


==Create and embed a template==
==Create and embed a template==
Line 35: Line 32:


==Describe parameters via TemplateData==
==Describe parameters via TemplateData==
The MediaWiki extension [[Manual:Extension/TemplateData|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.
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==
==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 [[Manual: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.
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==
==Further information==
Line 45: Line 42:
*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.)
*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.
*The complete list of all wiki pages that are in this namespace can be found on the <code>Special:Templates</code> page.
{{Box_Links | Topic1 = https://meta.wikimedia.org/wiki/Help:Template| Topic2 = https://www.mediawiki.org/wiki/Help:Templates| Topic 3= https://www.mediawiki.org/wiki/Help:Extension:ParserFunctions | Topic4 = }}
{{Box_Links-en| Topic1 = https://meta.wikimedia.org/wiki/Help:Template| Topic2 = https://www.mediawiki.org/wiki/Help:Templates| Topic 3= https://www.mediawiki.org/wiki/Help:Extension:ParserFunctions | Topic4 = }}
[[de:Handbuch:Vorlagen]]
[[de:Handbuch:Vorlagen]]
[[Category:Content]]
[[Category:Content]]
[[Category:Organization]]
[[Category:Organization]]

Revision as of 07:13, 3 April 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.