MediaWiki Transclusion — Templates, Parameters, Includeonly, and Noinclude
In this tutorial, you will learn about MediaWiki Transclusion. We cover key concepts, practical examples, and best practices to help you master this topic.
Transclusion in MediaWiki is the inclusion of content from one page into another using templates, parameters, inclusion control tags, and partial transclusion — the same mechanism that powers every infobox and navigation template on Wikipedia.
What You'll Learn
- How transclusion differs from copy-pasting
- Creating templates with named and positional parameters
- Using
<includeonly>,<noinclude>, and<onlyinclude>tags - Building a reusable information box
- Documenting templates so others can use them
Why It Matters
Transclusion is the most powerful concept in MediaWiki. Without it, every page that needs a "Note" box or a "Staff" list would require copy-pasting the same code. When you need to change the note style, you would have to edit every page manually. With transclusion, you write the content once and include it anywhere. Change the source, and every page that includes it updates automatically. This is the DRY (Don't Repeat Yourself) principle applied to wiki content.
Real-World Use
A DodaTech wiki has a "System Status" notice that appears at the top of 20 documentation pages. When the system status changes, the wiki admin edits one page — the "System Status" template — and all 20 pages update instantly. A "Quick Links" navigation box on the sidebar of 50 product pages is maintained the same way. Transclusion makes wiki maintenance scalable.
Learning Path
flowchart LR A["11: Advanced Wikitext"] --> B["12: Image & Media"] B --> C["13: Transclusion"] C:::current D["14: Parser Functions"] E["15: Subpages"] F["16: Redirects"] C --> D --> E --> F classDef current fill#38bdf8,color#0f172a,stroke-width:2px
What Is Transclusion?
The word "transclusion" combines "trans-" (across) and "inclusion" (including). It means including content from one page into another, not by copying it, but by referencing it.
When you write {{PageName}} on a page, MediaWiki fetches the content of "PageName" and inserts it at that point. If "PageName" changes, every page that uses {{PageName}} shows the updated content.
Source page: Template:Notice
Content: "The system will be down on Saturday."
Destination page: Installation Guide
Source: "{{Notice}}"
Rendered: "The system will be down on Saturday."
After editing Template:Notice to say "Sunday" instead of "Saturday":
Destination page now shows: "The system will be down on Sunday."
No copy-pasting. No manual updates. One change propagates everywhere.
The Three Inclusion Tags
MediaWiki provides three tags that control what happens when a page is transcluded.
<noinclude> — Show on Source, Hide on Target
Content inside <noinclude> tags appears on the source page but is NOT included when the page is transcluded elsewhere.
= Template:Notice =
<div class="notice">System maintenance this weekend.</div>
<noinclude>
[[Category:Notice templates]]
== Usage ==
Use this template to display maintenance notices.
</noinclude>
On Template:Notice, the category link and usage instructions are visible. When {{Notice}} is used on another page, only the div appears — the category and instructions are excluded.
Use <noinclude> for:
- Template documentation
- Categories that should only apply to the template itself
- Interlanguage links for the template page
- Examples showing how to use the template
<includeonly> — Hide on Source, Show on Target
Content inside <includeonly> tags is hidden on the source page but appears when transcluded.
= Template:Version =
<includeonly>Version {{{1}}} (stable)</includeonly>
On Template:Version, nothing is visible (the page appears empty). When {{Version|2.0}} is used on another page, it displays "Version 2.0 (stable)".
Use <includeonly> for:
- Content that only makes sense in context (category tags that should apply to the including page)
- Template logic that should not be visible on the template page itself
- Content that requires parameters to be meaningful
<onlyinclude> — Exclusive Inclusion
Content inside <onlyinclude> tags is the ONLY content included during transclusion. Everything outside these tags is excluded.
= MyPage =
<onlyinclude>
This is the reusable part.
</onlyinclude>
This part is only visible on MyPage itself, not when transcluded.
When another page uses {{MyPage}}, only "This is the reusable part." is included.
Use <onlyinclude> when:
- You want a page that is mostly display content but has a reusable section
- You want to include a specific portion of a page without creating a separate template
Combining Tags
The tags work together for complex scenarios:
<noinclude>
= Template:Infobox Product =
<pre>
{{Infobox Product
|name=Product Name
|version=1.0
}}
</pre>
</noinclude>
<includeonly>{| class="wikitable" style="float:right;width:300px;"
|+ {{{name|Product}}}
|-
! Version || {{{version|N/A}}}
|-
! Status || {{{status|Stable}}}
|}</includeonly>
On the template page, you see documentation and a usage example. When transcluded, only the infobox table appears.
Transclusion with Parameters
Parameters make transclusion dynamic. Instead of showing the same content everywhere, templates accept input.
Positional Parameters
= Template:Greeting =
Hello, {{{1}}}! Welcome to {{SITENAME}}.
Usage: {{Greeting|Alice}} renders "Hello, Alice! Welcome to My Wiki."
Parameters are numbered 1, 2, 3, etc. If not provided, {{{1}}} displays literally. Add a default:
= Template:Greeting =
Hello, {{{1|World}}}! Welcome to {{SITENAME}}.
Now {{Greeting}} renders "Hello, World! Welcome to My Wiki."
Named Parameters
= Template:UserInfo =
{| class="wikitable"
! Name || {{{name}}}
|-
! Role || {{{role}}}
|-
! Department || {{{dept|General}}}
|}
Usage:
{{UserInfo
|name=Alice
|role=Developer
|dept=Engineering
}}
Named parameters are self-documenting — the person using the template can see what each value means.
Default Values
The pipe syntax {{{param|default}}} provides a fallback:
{{{1}}} Required — no default, shows literal if missing
{{{1|}}} Optional — empty default
{{{1|N/A}}} Optional — "N/A" if not provided
{{{name|World}}} Named parameter with default
Always provide defaults when a parameter is optional. Required parameters should have no default so the template creator sees {{{1}}} in the output if they forget to supply a value.
Partial Transclusion
Sometimes you want only a section of a page, not the whole thing. Use <section> tags with the Extension:Labeled Section Transclusion, or use <onlyinclude> more precisely.
Basic partial transclusion with <onlyinclude>:
= Installation Guide =
== Overview ==
This guide covers installation on Linux.
<onlyinclude>
== Quick Start ==
Run the following command:
<syntaxhighlight lang="bash">
sudo ./install.sh
</syntaxhighlight>
</onlyinclude>
== Troubleshooting ==
If installation fails, check the logs.
Now {{Installation Guide}} includes only the "Quick Start" section. The overview and troubleshooting sections are excluded.
Template Documentation Best Practices
Every template should include documentation so others know how to use it. Use <noinclude> to add docs without affecting transclusion:
<noinclude>
= Template:Infobox Product =
== Usage ==
<pre>
{{Infobox Product
|name=Product Name
|version=1.0
|status=Stable
|description=A brief description of the product.
}}
</pre>
== Parameters ==
; name: Product name (required)
; version: Current version (required)
; status: Release status (default: Stable)
; description: Short description (optional)
</noinclude>
<includeonly>
{| class="wikitable" style="float:right;width:300px;"
|+ {{{name}}}
|-
! Version || {{{version}}}
|-
! Status || {{{status|Stable}}}
|-
! Description || {{{description|}}}
|}
</includeonly>
This standard format includes:
- A usage example with all parameters
- Parameter descriptions with required/optional status
- Default values where applicable
Transclusion and Substitution
Normal transclusion updates automatically when the source changes. Substitution copies the content permanently.
{{TemplateName}} Transclusion — updates with source
{{subst:TemplateName}} Substitution — copies content, no future updates
Use subst: when:
- You want a permanent snapshot of the template output
- The template will be deleted but you want existing usages to keep working
- Performance is critical and you want to avoid template Parsing overhead
Once substituted, the page contains the literal output of the template and has no further connection to it.
What You Learned
- Transclusion includes content by reference, not by copying
<noinclude>excludes content from transclusion<includeonly>shows content only during transclusion<onlyinclude>limits transclusion to specific content- Parameters make templates dynamic with default values
- Template documentation belongs inside
<noinclude> - Substitution copies content permanently
In the next lesson, you'll learn about parser functions — MediaWiki's built-in programming language for conditional logic, calculations, and string manipulation.
Common Mistakes
| Mistake | Why It Happens | How to Fix |
|---|---|---|
Template content appears on the including page with raw {{{1}}} displayed |
Missing parameter value | Provide the parameter value or add a default. {{{1\|}}} shows nothing if not provided. {{{1\|N/A}}} shows N/A. |
<noinclude> content appears on the target page |
Tag is closed incorrectly | Ensure <noinclude> and </noinclude> are on their own lines. The tags must be properly nested and closed. |
| Template shows nothing on the source page | All content is inside <includeonly> |
This is intentional behavior. The template page appears empty because all display content is wrapped in <includeonly>. Add documentation outside the tags. |
| Transcluded content does not update | Page cache | Append ?action=purge to the including page URL to force a cache refresh. Template changes do not automatically purge pages that use them. |
{{subst:...}} shows raw code instead of rendered output |
Syntax error | Check that the template exists and is spelled correctly. subst: applies to the rendered template output, not the source code. |
Practice Questions
- What is the difference between
<noinclude>and<includeonly>? Give a use case for each. - Create a template called "Status" that accepts a
statusparameter and displays a green "Online" or red "Offline" message based on the value. - How would you create a template that transcludes content from another page but only shows the first three sections?
- Challenge: Build a complete "Staff Directory" system. Create a template called
StaffMemberwith parameters for name, role, department, email, and photo. The template should render a formatted card. Then create 3 staff member pages that use the template with different data. Create a "Staff Directory" page that transcludes all three. Finally, add a category tag inside<includeonly>so the staff directory page is automatically categorized.
FAQ
Mini Project
Goal: Build a reusable "Alert Box" template system with three severity levels.
- Create
Template:Alertwith atypeparameter (info, warning, error) and amessageparameter - Use
{{#switch:...}}or CSS to style each type differently:- Info: blue background
- Warning: yellow background
- Error: red background
- Add
<noinclude>documentation showing usage examples - Add a category inside
<includeonly>that categorizes pages using the template - Create three test pages, each using the template with a different severity type
- Verify that categorizing works — all three test pages appear in the category
- Change the template style and verify all three pages update automatically
What's Next
Templates with parameters are powerful, but they become truly intelligent when combined with parser functions.
Continue to Lesson 14: Parser Functions — learn how to add conditional logic, switch statements, calculations, and date formatting to your templates.
Built by the developers of DodaTech
Doda Browser, DodaZIP & Durga Antivirus Pro