MediaWiki templates boost consistency, ease content management, and streamline wiki updates, improving efficiency and creating a cohesive user experience.
In MediaWiki, templates are pre-formatted pieces of text that can be included in other pages. Templates are technically pages in the Template namespace, so they can be created and edited using the same editor as regular pages. There is a special syntax for including templates and passing parameters via templates to the MediaWiki parser.
For example, you do not need to insert a picture of Merlin and a “Helpful Hint” label into each block. Instead, insert them into the Helpful Hint template once, and then provide the block with only variable content:
{{Helpful hint | Hint text here ... }}
Templates play a crucial role in MediaWiki by enabling users to uniformly apply identical content or formatting across numerous pages. This uniformity aids in preserving a consistent appearance and user experience throughout the wiki, simplifying the processes of content addition and modification. Furthermore, templates minimize redundant efforts, as any modifications to a template are instantaneously propagated to every page utilizing that template. This efficiency is particularly beneficial in the management of extensive and large wikis, saving time and streamlining content management.
MediaWiki templates are commonly used for a variety of purposes, including:
There are two main ways to reference a template in MediaWiki: using the "transclusion" syntax, which looks like this:
{{TemplateName}}
or using the "substitution" syntax, which looks like this:
{{subst:TemplateName}}
The transclusion syntax tells MediaWiki to insert the content of the template directly into the page. This means that any updates to the template will automatically be reflected on the pages that use it.
The substitution syntax, on the other hand, tells MediaWiki to copy the content of the template into the page and treat it as regular page content. This means that any updates to the template will not be reflected on the pages that use it.
In addition to simply inserting content, templates can also accept parameters, which allow you to customize the content that is inserted. These templates features can make it easier to create complex, structured content.
The values of template parameters can be queried by other extensions (eg. DynamicPageList3) and even stored aside of the page content (eg. Semantic MediaWiki) for the fine-grained grouping or filtering of pages. Other extensions (VisualEditor, PageForms) can provide forms for the guided input of the template values.
To use parameters in a MediaWiki template, you first need to define the parameters in the template's code. After that, you will be able to pass values to the inline template call.
For example, one can design a generic hint template that inserts specific image and label as required by the context. In the above example, you can add the “Hint type” parameter like this:
{{Hint | Hint type=Observe | Hint text here ... }}
{{Hint | Hint type=Helpful hint | Hint text here ... }}
{{Hint | Hint type=Caution | Hint text here ... }}
This way, the template does the formatting job, letting the editor to focus on the hint content. To achieve this, the template code must have a kind of logical expression (simplified):
{{#switch: {{{Hint type|}}} |Caution = Variable content (image and label) here ... |Helpful hint = Variable content (image and label) here ... |Observe = Variable content (image and label) here ... |#default = Image and label to be used if no value is provided for the parameter }}
In MediaWiki templates, the named and numbered parameters both allow you to specify a value that can be used in the template, but they differ in how they are specified and accessed. Named parameters are specified by using a name and an equals sign, like this:
{{template|name=value}}
They can be accessed in the template using the name, like this:
{{{name}}}
One advantage of named parameters is that they make it easier to understand the purpose of the parameter because the name provides a description:
{{templateName|name=John|age=35|occupation=Software Engineer}}
This can make templates easier to use and maintain.
Numbered parameters, on the other hand, are specified by just providing a value, without using a name.They are accessed in the template using their position, like this: {{{1}}}
for the first parameter, {{{2}}}
for the second parameter, and so on. Parameters are delimited with “|
” (pipe) symbol.
Numbered parameters are more compact and can be easier to use in some cases. For example, if you just want to specify a simple list of items, you can use numbered parameters without having to assign names to them, like this:
{{templateName|John|35|Software Engineer}}
In this example, the template has three numbered parameters, with the first one representing a person's name, the second one representing their age, and the third one representing their occupation.
In the previous example:
{{Hint | Hint type=Observe | Hint text here ... }}
There is one named parameter (“Hint type”) referred to in the template code as {{{Hint type}}}
, and one numbered parameter, referred to in the template code as {{{1}}}
although the parameter is in the second position in the template call. {{{1}}}
means “the first unnamed parameter” here.
{{{Author|Unknown author}}}
will render “Unknown author” if no name was provided inline.|
” (pipe) symbol: {{{Author|}}}
.We hope this blog provided the information on MediaWiki templates you were looking for. If you have any questions, feel free to leave a comment, reach out to us for a free consultation, or see if our other blogs have the answers to your questions!
Here’s what we've been up to recently.
Struggling with knowledge management in your organization? Our latest blog, Overcoming Knowledge Management Challenges: Strategies for Success, is here to help! From breaking down silos to ensuring up-to-date, accessible information, we explore common hurdles and provide actionable strategies to enhance your KM practices. Discover how you can foster a knowledge-sharing culture, improve accessibility, and measure the impact of KM initiatives to drive organizational success.
In today’s data-driven world, a company's most valuable asset is its data. Properly managed, it can reveal critical insights about customers, operations, and market dynamics, positioning the company ahead of its competition. However, with the average organization managing an overwhelming 400 data sources, the challenge of effectively harnessing this data becomes clear.
In today’s fast-paced business environment, efficiency is no longer a luxury but a necessity. One of the most effective ways to drive efficiency is through centralized knowledge management. This approach ensures that all organizational knowledge is stored, accessed, and shared from a single, cohesive system, allowing businesses to operate more smoothly and make informed decisions quickly. - use as featured?
From us to your inbox weekly.
We use cookies to provide and improve our services. By using our site, you consent to cookies.
Learn more