Jump to content

Help:Transclusion

From Encyc

Transclusion is a powerful MediaWiki feature that allows you to include the content of one page within another page. Instead of copying and pasting content, transclusion dynamically pulls content from a source page, ensuring that updates to the source are automatically reflected everywhere it's used.

What is Transclusion?

[edit source]

Transclusion embeds the content of one wiki page into another. When the source page is updated, all pages that transclude it are automatically updated as well.

Benefits:

  • Maintains consistency across multiple pages
  • Reduces duplicate content
  • Makes site-wide updates easier
  • Saves time and effort

Basic Syntax

[edit source]
Syntax Description
{{PageName}} Transclude a page from the Template namespace
{{:PageName}} Transclude a page from the main namespace
{{Namespace:PageName}} Transclude from a specific namespace

Examples

[edit source]
{{Welcome}}             <!-- Transcludes Template:Welcome -->
{{:Main Page}}          <!-- Transcludes the Main Page article -->
{{Help:Contents}}       <!-- Transcludes Help:Contents -->
{{User:John/Signature}} <!-- Transcludes a user subpage -->

Types of Transclusion

[edit source]

Template Transclusion

[edit source]

The most common form. Templates are pages in the Template: namespace designed to be transcluded.

{{Infobox}} {{Navbox}} {{Stub}}

Article Transclusion

[edit source]

Include content from regular articles using a colon prefix:

{{:Article Name}}

Special Namespace Transclusion

[edit source]

Transclude from any namespace by specifying it:

{{Wikipedia:Manual of Style}} {{Help:Editing}}

Using Templates

[edit source]

Creating a Template

[edit source]
  1. Create a page titled Template:YourTemplateName
  2. Add your content
  3. Save the page

Example Template:Greeting

Hello and welcome to our wiki! We're glad you're here.

Using the Template

[edit source]

{{Greeting}}

Output:

Hello and welcome to our wiki! We're glad you're here.

Controlling Transcluded Content

[edit source]

You can control which parts of a page are transcluded using special tags:

noinclude

[edit source]

Content inside these tags appears only on the original page, not when transcluded.

This text appears everywhere.
<noinclude>
This text only appears on the template page itself.
[[Category:Templates]]
</noinclude>

includeonly

[edit source]

Content inside these tags appears only when transcluded, not on the original page.

<includeonly>
This text only appears on pages that transclude this template.
</includeonly>

onlyinclude

[edit source]

Only content inside these tags will be transcluded. Everything else is excluded.

This won't be transcluded.
<onlyinclude>
Only this content will be transcluded.
</onlyinclude>
This also won't be transcluded.

Summary Table

[edit source]
Tag On Template Page When Transcluded
<noinclude> Visible Hidden
<includeonly> Hidden Visible
<onlyinclude> Visible Visible (only this content)

Parameters

[edit source]

Templates can accept parameters to customize their output.

Unnamed Parameters

[edit source]

Template:Greeting

Hello, {{{1}}}! Welcome to {{{2}}}.

Usage:

{{Greeting|John|our wiki}}

Output:

Hello, John! Welcome to our wiki.

Named Parameters

[edit source]

Template:UserInfo

'''Name:''' {{{name}}}
'''Role:''' {{{role}}}
'''Joined:''' {{{joined}}}

Usage:

{{UserInfo|name=Jane Smith|role=Editor|joined=January 2024}}

Default Values

[edit source]

Provide fallback values if a parameter isn't supplied:

Hello, {{{name|Guest}}}!

If name is not provided, it displays "Guest".

Checking if Parameter Exists

[edit source]

Using parser functions:

{{#if:{{{image|}}}|[[File:{{{image}}}]]|No image available}}

Substitution vs Transclusion

[edit source]

Transclusion

[edit source]

{{Template}}

  • Content is dynamically pulled each time the page loads
  • Updates to template automatically appear everywhere
  • Use for content that should stay synchronized

Substitution

[edit source]

{{subst:Template}}

  • Content is copied and permanently inserted
  • Changes to template do NOT affect substituted content
  • Use for one-time insertions (like welcome messages)
{{subst:Welcome}}    <!-- Substitutes content permanently -->

Common Examples

[edit source]
[edit source]

Template:ProjectNav

<div class="navbox">
'''Project Navigation'''
[[Project:About|About]] | [[Project:Guidelines|Guidelines]] | [[Project:Help|Help]]
</div>
<noinclude>
[[Category:Navigation templates]]
</noinclude>

Infobox

[edit source]

Template:Infobox Person

{| class="infobox"
|-
! colspan="2" | {{{name|Unknown}}}
|-
| '''Born''' || {{{birth_date|Unknown}}}
|-
| '''Occupation''' || {{{occupation|Unknown}}}
|}
<noinclude>
==Usage==
{{Infobox Person
|name=
|birth_date=
|occupation=
}}
[[Category:Infobox templates]]
</noinclude>

Warning/Notice Boxes

[edit source]

Template:Warning

<div class="warning-box" style="background:#ffe0e0; border:1px solid red; padding:10px;">
⚠️ '''{{{1|Warning}}}'''
</div>

Usage: {{Warning|This article contains spoilers}}

Stub Template

[edit source]

Template:Stub

<div class="stub">
''This article is a stub. You can help by [{{fullurl:{{FULLPAGENAME}}|action=edit}} expanding it].''
</div>
<includeonly>
[[Category:Stub articles]]
</includeonly>
<noinclude>
[[Category:Notice templates]]
</noinclude>

Troubleshooting

[edit source]

Common Issues

[edit source]
Problem Cause Solution
{{Template}} shows as text Template doesn't exist Create the template page
Content not appearing Wrong namespace Use correct prefix (: for main namespace)
Parameters not working Wrong syntax Check for typos in {{{parameter}}}
Changes not reflecting Page caching Purge the page cache
Circular transclusion error Page includes itself Remove self-reference

Purging Cache

[edit source]

If changes to a template aren't appearing, purge the cache:

  • Add ?action=purge to the URL
  • Or click "Purge" if available in your wiki's interface

Viewing Transcluded Pages

[edit source]

To see which pages transclude a template:

  1. Go to the template page
  2. Click "What links here" in the sidebar
  3. Look for pages that transclude this template

Best Practices

[edit source]
  1. Document your templates - Add usage instructions in <noinclude> tags
  2. Use descriptive parameter names - {{{author}}} is clearer than {{{1}}}
  3. Provide default values - Prevents broken output if parameters are missing
  4. Categorize templates - Keep templates organized
  5. Test before saving - Use the Preview button
  6. Keep templates focused - One purpose per template

See Also

[edit source]