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: | ||
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. | |||
== Using templates == | |||
Templates can provide either reusable content or reusable structures. A template can also combine both. <br> | |||
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 | *fixed content | ||
[[File: | *parameters for variable content | ||
== | *formatting | ||
*conditional logic <br> | |||
Templates are commonly used to maintain a consistent look and feel across multiple pages. | |||
[[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]] | |||
== Create and insert a template == | |||
=== Create a template === | |||
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. | |||
== | === Insert a template === | ||
A | 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''': | |||
#Open the page in '''VisualEditor'''. | |||
#Select '''Insert'''. | |||
#Select '''Template'''. | |||
==Edit a template== | #Enter the name of the template. | ||
Changes to a template affect all pages that contain | #Enter values for the available parameters, if required. | ||
#Insert the template. | |||
==Built-in variables== | ==== 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'''. | |||
#Open the page in '''VisualEditor'''. | |||
For example | #Open the '''Content droplet''' menu. | ||
#Select the template. | |||
== | #Enter values for the available parameters, if required. | ||
==== In wikitext ==== | |||
To insert a template in wikitext, enclose the template name in two curly brackets: | |||
==Format template== | <syntaxhighlight lang="text"> {{NotificationBox}} </syntaxhighlight> | ||
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. <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> | |||
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. <br> | |||
To find pages that use a template: | |||
#Open the template page. | |||
#Open '''More page actions'''. | |||
#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.
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:
- Open the page in VisualEditor.
- Select Insert.
- Select Template.
- Enter the name of the template.
- Enter values for the available parameters, if required.
- 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.
- Open the page in VisualEditor.
- Open the Content droplet menu.
- Select the template.
- 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:
- Open the template page.
- Open More page actions.
- 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.
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.
- Open Wiki actions.
- 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.