Skip to content

MediaWiki Templates — Reusable Content Blocks for a Consistent Wiki

DodaTech Updated 2026-06-26 7 min read

In this tutorial, you'll create reusable templates on your MediaWiki wiki, starting with a simple notice box and building up to a full infobox with parameters. This is Lesson 5 of our project: Build Your Own Documentation Wiki.

What You'll Build Today

By the end of this lesson, your wiki will have:

  • A notice template for warnings and tips
  • A software infobox template with 5 parameters
  • The infobox used on 2 different pages with different data

You'll never type the same formatting twice again.

Why Templates Matter

Imagine you need to add a "Note" box to 10 different pages. Without templates, you'd copy-paste the same HTML or wikitext 10 times. When you want to change the color of the note box, you'd need to edit all 10 pages.

With a template, you write the formatting once and use it everywhere. Change the template, and all pages that use it update automatically.

Think of templates like functions in programming: you define the logic once and call it with different data.

Step-by-Step: Create Your First Template

Step 1: Understand the Template Namespace

Templates live in the Template: namespace. A template called "Note" lives at Template:Note. You use it on a page by writing {{Note}}.

Let's create one.

Step 2: Create a Simple Notice Template

  1. Go to http://localhost/<a href="/cms/mediawiki/">MediaWiki</a>/index.php/Template:Note
  2. This is a red link — the template doesn't exist yet. Click "Create"
  3. Add this content:
<div style="border:1px solid #4fc3f7;border-radius:8px;padding:12px 16px;background:#e1f5fe;color:#01579b;margin:12px 0;">
'''Note:''' {{{1|}}}
</div>
  1. Write an edit summary: Created Note template
  2. Click "Publish changes"

Let's understand what you just wrote:

Part Meaning
<div style="..."> HTML styling for a blue notice box
'''Note:''' Bold label "Note:"
{{{1\|}}} Parameter 1, with empty default

The {{{1|}}} syntax means "use the first parameter, or nothing if it's not provided." The pipe | followed by nothing sets the default to empty.

Step 3: Use Your Template

Go to your Project Setup Guide page and edit it. Add this line at the top:

{{Note|Make sure you have admin access before following these steps.}}

Save the page. You should see a blue box at the top with:

Note: Make sure you have admin access before following these steps.

â„šī¸ Info

The template rendered your text inside the styled div. You used the template with one line — imagine typing that div by hand on every page.

Step 4: Add a Second Parameter

Edit Template:Note and add a type parameter:

<div style="border:1px solid {{{2|#4fc3f7}}};border-radius:8px;padding:12px 16px;background:{{{3|#e1f5fe}}};color:{{{4|#01579b}}};margin:12px 0;">
'''{{{2-type|Note}}}:''' {{{1|}}}
</div>

Wait, that's getting complicated with 4 parameters. Let's use named parameters instead — they're easier to remember.

Replace the template content with:

<div style="border:1px solid {{#switch:{{{type|info}}}
  |info = #4fc3f7
  |warning = #ff9800
  |error = #f44336
}};border-radius:8px;padding:12px 16px;background:{{#switch:{{{type|info}}}
  |info = #e1f5fe
  |warning = #fff3e0
  |error = #ffebee
}};color:{{#switch:{{{type|info}}}
  |info = #01579b
  |warning = #e65100
  |error = #b71c1c
}};margin:12px 0;">
'''{{#switch:{{{type|info}}}
  |info = Note
  |warning = Warning
  |error = Error
}}:''' {{{1|}}}
</div>

Now you can use it with a named parameter:

{{Note|type=warning|This is a warning message.}}
{{Note|type=error|This is an error message.}}
{{Note|This is a plain note.}}
â„šī¸ Info

The {{#switch:...}} syntax is a parser function — MediaWiki's built-in programming language. It works like a switch/case statement in PHP or JavaScript. We'll explore more in the advanced lessons.

Step 5: Create an Infobox Template

An infobox is a table that appears at the top-right of many wiki pages, showing key information in a consistent format. Let's create one for software tools.

Create a new page at Template:Infobox Software with this content:

{| class="wikitable" style="float:right;width:300px;margin-left:15px;font-size:90%;"
|+ '''{{{name|Software Name}}}'''

{{#if:{{{developer|}}}|
! Developer
| {{{developer}}}
|-
}}
{{#if:{{{version|}}}|
! Latest Version
| {{{version}}}
|-
}}
{{#if:{{{release|}}}|
! Release Date
| {{{release}}}
|-
}}
{{#if:{{{license|}}}|
! License
| {{{license}}}
|-
}}
{{#if:{{{website|}}}|
! Website
| [{{{website}}} {{{website|}}}]
|-
}}
|}

This looks complex, but it's just a wiki table with parameters. Let's break it down:

| Part | What It Does | |------|-------------| | {| class="wikitable" | Start a table with standard wiki styling | | \|+ '''{{{name\|}}}''' | Table caption — the software name | | {{#if:{{{developer\|}}}|...}} | Only show the row if a value is provided | | ! Developer | Table header cell | | {{{developer}}} | The value of the developer parameter | | {{!}}- | New table row | | {{!}}} | End the table |

The {{#if:...}} parser function checks if the parameter has a value. If it does, the row is shown. If not, the row is hidden entirely. This means your infobox only shows the fields you fill in.

Step 6: Use the Infobox Template

Edit your API Reference page. Add this at the very top (before any other content):

{{Infobox Software
|name      = DodaTech API
|developer = DodaTech
|version   = 2.1.0
|release   = 2026-06-01
|license   = MIT
|website   = https://api.dodatech.com
}}

Save the page. You should see a table on the right side showing the API's name, developer, version, release date, license, and website — all formatted consistently.

Step 7: Use the Infobox on Another Page

Edit your Project Setup Guide page. Add at the top:

{{Infobox Software
|name      = Setup Tool
|version   = 1.0.0
|license   = Proprietary
}}

Save and notice:

  • Only the fields you provided are shown (developer and website are hidden)
  • The infobox has the same structure as the one on API Reference
  • If you later update the template, both pages update automatically

What You Learned

  • Templates live in the Template: namespace
  • {{{1}}} is a positional parameter, {{{name}}} is a named parameter
  • {{{param|default}}} sets a default value
  • {{#if:...}} conditionally shows content
  • {{#switch:...}} selects content based on a value
  • Templates can contain wikitext, HTML, and parser functions

In the next lesson, you'll learn about namespaces — how MediaWiki organizes different types of pages.

Common Errors

| Error | Why It Happens | How to Fix | |-------|---------------|------------| | {{TemplateName}} displays as raw text instead of rendering | The template page doesn't exist yet | Create the template at Template:TemplateName. The curly brace syntax only works for existing templates. | | {{{1}}} appears in the rendered page | You forgot to provide the parameter value | Check your template call. If the template uses {{{1}}}, you need to call it with {{Template|value}}. | | "Template loop detected" | Template A calls Template B, which calls Template A | This is a circular reference. Break the loop by removing one of the template calls. | | Infobox shows on the wrong side of the page | The float:right CSS isn't working | Make sure your table uses style="float:right" and not align="right". Also check that the infobox is placed BEFORE the main content. | | {{#if:...}} not working | Incorrect syntax | The format is {{#if:condition|then|else}}. Make sure you have exactly one colon after #if. | | Template changes don't appear on pages | Page cache | Append ?action=purge to the page URL to force a cache refresh. Example: http://localhost/mediawiki/index.php/MyPage?action=purge |

FAQ

Can templates have default values?

Yes. {{{param|default}}} — if the user doesn't provide a value, "default" is used. If you write {{{param|}}}, the default is empty and the row won't show if you use {{#if:...}}.

How do I document a template so others know how to use it?

Add a <noinclude> section at the bottom of the template page. Anything inside <noinclude> is not included when the template is used:

<noinclude>
== Usage ==
{{Infobox Software
|name=Name
|developer=Dev
}}
</noinclude>

Can I use templates inside other templates?

Yes, this is called template nesting and it's very powerful. For example, a "Warning" template could call the "Note" template with type=warning. Just be careful not to create circular references.

How do I edit a template without affecting pages that use it?

You can't — that's the point of templates. Changes apply immediately to all pages. To test changes safely, create a sandbox copy at Template:TemplateName/Sandbox and test there first.

What is {{subst:TemplateName}}?

The subst: prefix substitutes the template's content permanently at the time of saving. After that, the page has a copy of the template and won't update if the template changes. Use this when you want a one-time expansion, not a live link.

What's Next

Your wiki now has reusable templates. But as your wiki grows, you'll need to organize different types of content — articles, discussions, user profiles, help pages. MediaWiki uses namespaces for this.

Continue to Lesson 6: Namespaces — Organizing Different Types of Content — understand how namespaces work and when to use each one.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro