6.3 Templates

(Created page with "<bookshelf src="Book:User manual" />")
 
No edit summary
Tag: 2017 source edit
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.
[[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]].
==Characteristics of a template==
Features of a template:<!-- Transferred to training materials! -->
<section begin="training" />
*[[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)
*usually located in the "Template" namespace
*can have parameters
*often contains logic
*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 [[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.
==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.
==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 | 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]]
[[Category:Content]]
[[Category:Organization]]

Revision as of 08:08, 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. Example of an infobox template


A template can also be integrated into a page template.

Characteristics of a template

Features of a template:

  • Source text view of an integrated templateallows you to insert reusable content with a placeholder (transclusion)
  • usually located in the "Template" namespace
  • can have parameters
  • often contains logic
  • 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.

Template:Box Links




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

Discussions