Meryam Sahin (talk | contribs)
Created page with "==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. File:Template IMS Work instruction.png|alt=scre..."
 
Meryam Sahin (talk | contribs)
No edit summary
Line 1: Line 1:
==What is a template?==
Templates provide reusable content that can be embedded in multiple wiki pages. They can contain text, formatting, page structures, or a combination of these. Templates are useful for maintaining consistent content and formatting across pages, such as for infoboxes. <br>
 
Templates are usually stored in the '''Template''' namespace. They can be used locally within a wiki or stored in the [[SharedResources|'''Shared resources''']] wiki to make them available across wikis.
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.
== Using templates ==
 
Templates can provide either reusable content or reusable structures. A template can also combine both. <br>
A typical example is an infobox that is formatted to look identical on all pages.
A template is embedded in a page through [https://www.mediawiki.org/wiki/Transclusion transclusion]. When a page contains a template, the template content is included when the page is rendered. <br>
 
Templates can contain:
A template can also be integrated into a [[Manual:Extension/BlueSpicePageTemplates|page template]].
*fixed content
[[File:Template IMS Work instruction.png|alt=screenshot of a work instruction|center|thumb|650x650px|Document control box at the beginning of a document]]
*parameters for variable content
==Characteristics of a template==
*formatting
A template:
*conditional logic <br>
*allows you to insert reusable content with a placeholder (transclusion)
Templates are commonly used to maintain a consistent look and feel across multiple pages.
*is usually located in the "Template" namespace
[[File:template-document-control-box.png|alt=Document control box at the beginning of a document|center|thumb|650x650px|Document control box created with reusable template content]]
*can have parameters
== Create and insert a template ==
*often contains logic
=== Create a template ===
*is used to maintain a "look and feel".
Create the template in the '''Template''' namespace. <br>
 
A template can contain fixed content as well as parameters. Parameters allow different values to be supplied when the template is inserted on a page.
==Create and embed a template==
=== Insert a template ===
A new template is always created in the <code>Template</code> namespace.
A template can be inserted into a page in '''VisualEditor''', as a '''Content droplet''', or directly in wikitext.
 
==== In VisualEditor ====
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:
To insert a template in '''VisualEditor''':
* the Insert menu item of the [[Manual:Extension/VisualEditor|editor toolbar]]
#Open the page in '''VisualEditor'''.
* as a [[Manual:Extension/ContentDroplets|Content droplet]]
#Select '''Insert'''.
 
#Select '''Template'''.
==Edit a template==
#Enter the name of the 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.
#Enter values for the available parameters, if required.
 
#Insert the template.
==Built-in variables==
==== As a Content droplet ====
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.
Templates can also be inserted as '''Content droplets''' when the template has been configured as a '''Content droplet''' by an administrator. Not all templates are available as '''Content droplets'''.
 
#Open the page in '''VisualEditor'''.
For example, the variable <tt><nowiki>{{CURRENTTIME}}</nowiki></tt> returns the current UTC time.
#Open the '''Content droplet''' menu.
 
#Select the template.
==Describe parameters via TemplateData==
#Enter values for the available parameters, if required.
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.
==== In wikitext ====
 
To insert a template in wikitext, enclose the template name in two curly brackets:
==Format template==
<syntaxhighlight lang="text"> {{NotificationBox}} </syntaxhighlight>
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.
When the page is rendered, the template content is included in the page.
 
=== Use template parameters ===
==Further information==
Template parameters allow a template to display different values or content depending on how it is used. <br>
 
For example, a template can provide parameters for a title, status, or other values that differ between pages. The available parameters depend on the template definition. <br>
*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.
When a template is inserted through '''VisualEditor''', available parameters can be entered in the template dialog.
*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.)
== Edit a template ==
*The complete list of all wiki pages that are in this namespace can be found on the <code>Special:Templates</code> page.
Changes to a template affect all pages that contain the template. Check which pages use a template before modifying it to assess the potential impact of the change. <br>
{{Box_Links-en| Topic1 = https://www.mediawiki.org/wiki/Help:Templates| Topic2 = https://www.mediawiki.org/wiki/Help:Extension:ParserFunctions| Topic 3=  | Topic4 = }}
To find pages that use a template:
[[de:Handbuch:Vorlagen]]
#Open the template page.
[[Category:Content]]
#Open '''More page actions'''.
[[Category:Organization]]
#Select '''...all actions''' > '''Links to this page'''.
#Review the listed pages before making changes to a template that is used on multiple pages.
== Built-in variables ==
MediaWiki provides built-in variables that can be used in templates. Built-in variables are not pages in the '''Template''' namespace, but they use a similar syntax. <br>
For example:
<syntaxhighlight lang="text"> {{CURRENTTIME}} </syntaxhighlight>
CURRENTTIME returns the current time in UTC. <br>
For more information about built-in variables, see [[Magic Words|Magic Words]].
== TemplateData ==
TemplateData describes the parameters of a template. This information allows the '''VisualEditor''' to provide parameter names, descriptions, and other details when a template is inserted or edited. <br>
TemplateData can define information such as:
*parameter name
*label
*description
*expected value <br>
When TemplateData is available, VisualEditor provides a form for entering the corresponding parameter values. For more information, see [https://www.mediawiki.org/wiki/Help:TemplateData TemplateData] in the MediaWiki documentation.
== Format a template ==
Template formatting can be defined with CSS. <br>
For styles that are used by multiple templates within the same wiki, add the styles to the wiki's [[MediaWiki:Common.css]] page. Each wiki has its own <code>MediaWiki:Common.css</code>. In a Galaxy environment with a main wiki and subwikis, changes to MediaWiki:Common.css in one wiki do not automatically apply to the other wikis. <br>
For styles that apply only to a specific template, use [https://www.mediawiki.org/wiki/Extension:TemplateStyles TemplateStyles]. '''TemplateStyles''' allows CSS to be stored with the template, typically on a subpage of the template. <br>
Storing template-specific styles with '''TemplateStyles''' can simplify moving a template and its styles between wikis.
== Templates in Shared resources ==
Templates can be stored in the [[Shared resources|'''Shared resources''']] wiki and shared across wikis. <br>
'''Shared resources''' is a central wiki for content that is available across multiple wikis. In addition to templates, images and other files can be shared through Shared resources.
== View available templates ==
The available templates can be viewed from the '''Wiki actions''' menu.
#Open '''Wiki actions'''.
#In the '''Overview''' section, select '''Templates'''. <br>
The '''Templates''' option opens <code>Special:AllPages</code> with the Template namespace preselected. The page lists the pages currently available in the '''Template''' namespace.
== Further information ==
Pages outside the Template namespace can technically be used as templates. However, some template-related functionality requires templates to be located in the Template namespace. <br>
Templates can also be used with the [[Extension/Forms|Forms]] extension. <br>
For information about '''Page templates''', see [[Extension/BlueSpicePageTemplates|Page templates]].<br>
For information about '''Shared templates''' and other content, see [[Shared resources|Shared resources]].<br>​For more information about templates and their syntax, see [https://www.mediawiki.org/wiki/Help:Templates Templates] in the MediaWiki documentation.

Revision as of 10:07, 31 August 2026

Templates provide reusable content that can be embedded in multiple wiki pages. They can contain text, formatting, page structures, or a combination of these. Templates are useful for maintaining consistent content and formatting across pages, such as for infoboxes.
Templates are usually stored in the Template namespace. They can be used locally within a wiki or stored in the Shared resources wiki to make them available across wikis.

Using templates

Templates can provide either reusable content or reusable structures. A template can also combine both.
A template is embedded in a page through transclusion. When a page contains a template, the template content is included when the page is rendered.
Templates can contain:

  • fixed content
  • parameters for variable content
  • formatting
  • conditional logic

Templates are commonly used to maintain a consistent look and feel across multiple pages.

Document control box at the beginning of a document
Document control box created with reusable template content

Create and insert a template

Create a template

Create the template in the Template namespace.
A template can contain fixed content as well as parameters. Parameters allow different values to be supplied when the template is inserted on a page.

Insert a template

A template can be inserted into a page in VisualEditor, as a Content droplet, or directly in wikitext.

In VisualEditor

To insert a template in VisualEditor:

  1. Open the page in VisualEditor.
  2. Select Insert.
  3. Select Template.
  4. Enter the name of the template.
  5. Enter values for the available parameters, if required.
  6. Insert the template.

As a Content droplet

Templates can also be inserted as Content droplets when the template has been configured as a Content droplet by an administrator. Not all templates are available as Content droplets.

  1. Open the page in VisualEditor.
  2. Open the Content droplet menu.
  3. Select the template.
  4. Enter values for the available parameters, if required.

In wikitext

To insert a template in wikitext, enclose the template name in two curly brackets:

 {{NotificationBox}}

When the page is rendered, the template content is included in the page.

Use template parameters

Template parameters allow a template to display different values or content depending on how it is used.
For example, a template can provide parameters for a title, status, or other values that differ between pages. The available parameters depend on the template definition.
When a template is inserted through VisualEditor, available parameters can be entered in the template dialog.

Edit a template

Changes to a template affect all pages that contain the template. Check which pages use a template before modifying it to assess the potential impact of the change.
To find pages that use a template:

  1. Open the template page.
  2. Open More page actions.
  3. Select ...all actions > Links to this page.
  4. Review the listed pages before making changes to a template that is used on multiple pages.

Built-in variables

MediaWiki provides built-in variables that can be used in templates. Built-in variables are not pages in the Template namespace, but they use a similar syntax.
For example:

 {{CURRENTTIME}}

CURRENTTIME returns the current time in UTC.
For more information about built-in variables, see Magic Words.

TemplateData

TemplateData describes the parameters of a template. This information allows the VisualEditor to provide parameter names, descriptions, and other details when a template is inserted or edited.
TemplateData can define information such as:

  • parameter name
  • label
  • description
  • expected value

When TemplateData is available, VisualEditor provides a form for entering the corresponding parameter values. For more information, see TemplateData in the MediaWiki documentation.

Format a template

Template formatting can be defined with CSS.
For styles that are used by multiple templates within the same wiki, add the styles to the wiki's MediaWiki:Common.css page. Each wiki has its own MediaWiki:Common.css. In a Galaxy environment with a main wiki and subwikis, changes to MediaWiki:Common.css in one wiki do not automatically apply to the other wikis.
For styles that apply only to a specific template, use TemplateStyles. TemplateStyles allows CSS to be stored with the template, typically on a subpage of the template.
Storing template-specific styles with TemplateStyles can simplify moving a template and its styles between wikis.

Templates in Shared resources

Templates can be stored in the Shared resources wiki and shared across wikis.
Shared resources is a central wiki for content that is available across multiple wikis. In addition to templates, images and other files can be shared through Shared resources.

View available templates

The available templates can be viewed from the Wiki actions menu.

  1. Open Wiki actions.
  2. In the Overview section, select Templates.

The Templates option opens Special:AllPages with the Template namespace preselected. The page lists the pages currently available in the Template namespace.

Further information

Pages outside the Template namespace can technically be used as templates. However, some template-related functionality requires templates to be located in the Template namespace.
Templates can also be used with the Forms extension.
For information about Page templates, see Page templates.
For information about Shared templates and other content, see Shared resources.
​For more information about templates and their syntax, see Templates in the MediaWiki documentation.