Jump to content

Help:Transclusion

From Wikipedia

Transclusion

[edit]

Transclusion is the process of including the content of one page (usually a template) into another page. It helps reuse text, standardize layouts, and maintain consistency across many pages.

Basics

[edit]
  • To transclude a template, use double curly braces:
{{Template name}}
  • To transclude a regular page (not in Template: namespace), use:
{{:Page name}}
 The leading colon (:) is required for transcluding pages outside the Template namespace.
  • You can add parameters:
{{Template name|param1=value|param2=value}}

Where it works

[edit]
  • Works in most content pages: articles, project pages, user pages.
  • Also works in talk pages and documentation pages.
  • Transclusion inside tables, lists, and infoboxes is supported.
  • Some namespaces may restrict certain features depending on local configuration.

Parameters

[edit]

Parameters allow templates and transcluded pages to be customized.

  • Positional parameters:
{{Example|alpha|beta}}
 Mapped in the template to {{{1}}}, {{{2}}}, etc.
  • Named parameters:
{{Example|color=blue|size=large}}
 Accessed via {{{color}}} and {{{size}}}.
  • Defaults:
{{{color|red}}}
 Uses red if color is not provided.
  • Aliases:
{{{colour|{{{color|}}}}}}
 Accept either spelling, preferring colour, then color.

Transcluding pages

[edit]
  • From Template namespace:
{{Infobox person}}
  • From other namespaces:
{{:Help:Editing}}
  • From subpages:
{{:Wikipedia:Sandbox/Subpage}}
  • Avoid transcluding user pages into articles unless clearly necessary and policy-compliant.

Preventing transclusion

[edit]
  • Noinclude:
 Content inside <noinclude>…</noinclude> is visible only on the template page, not on pages that transclude it (commonly used for documentation and categories).
  • Includeonly:
 Content inside <includeonly>…</includeonly> appears only when the template is transcluded, not on its own page.
  • Onlyinclude:
 Content inside <onlyinclude>…</onlyinclude> is the only part transcluded; the rest is ignored.
  • Example:
  Template page:
  Intro text
  <noinclude>Docs and categories here.</noinclude>
  

Linking vs transcluding

[edit]
  • Link to a template page:
{{tl|Template name}}
 This shows the link without transcluding the template.
  • Link to a page instead of transcluding:
[[:Page name]]
 The leading colon prevents category additions or unintended behaviors.

Conditional logic

[edit]

Templates can adjust output based on parameters:

  • Basic if/else (ParserFunctions):
{{#if:{{{title|}}}|Has title: {{{title}}}|No title provided}}
  • Switch:
{{#switch:{{{status|}}}
   |yes=Enabled
   |no=Disabled
   |#default=Unknown
  }}

Transclusion and categories

[edit]
  • Categories in a template will categorize any page that transcludes it.
  • To avoid categorizing the template page itself, place categories inside on the template.
  • To categorize only the /doc page, put categories in the /doc subpage (which is normally d).

Nesting and recursion

[edit]
  • Templates can transclude other templates (nesting).
  • Avoid deep recursion and circular transclusion, which can cause errors or performance issues.
  • Check the Special:ExpandTemplates tool to debug complex nesting.

Performance considerations

[edit]
  • Heavy templates (infoboxes, citation systems) may be transcluded on thousands of pages.
  • Minimize expensive parser functions and deep nesting.
  • Cache: MediaWiki caches parsed output; changes may take time to propagate.
  • Purge a page to refresh: click “Purge” or add ?action=purge to the URL.

Internationalization

[edit]
  • Provide language-neutral parameters when possible.
  • For multilingual output, consider separate templates or Lua modules.
  • Document fallback rules on the template’s /doc page.

Lua (Scribunto)

[edit]
  • Some templates use Lua modules for logic.
  • Transclusion syntax is the same; parameters are passed through to the module.
  • See Wikipedia:Lua and Help:Lua.

Common mistakes

[edit]
  • Forgetting the leading colon when transcluding a non-template page (should be A page can be different things:
  • When we talk about computers, the page is also the common aabreviation in net jargon for "webpage". Here the page is not paper, it is the piece of information which we can see on the computer monitor at one time. We can print it to make the real page. But the information may not fit all on one page, and we can not change it when it is printed - we can change the web page. So the webpage is not always the same even as the printed copy of that page. This is the conceptual metaphor. It can be confusing. Someone who uses it is also likely to use other jargon.
  • A page is also the boy or the young man who helps carry things and does small jobs for someone. Another word for this is the pageboy.
  • To page someone is to contact that person on air pager: this is the small electronic machine which makes the sound or gives someone the message.

guided tour test guided tour test guided tour test

https://test2.wikipedia.org/wiki/O





).

  • Categorizing articles unintentionally via a template.
  • Using ambiguous parameter names without documentation.
  • Overloading templates with complex logic that belongs in Lua.

Examples

[edit]

Minimal:

{{Template:Hello}}

With parameters:

{{Hello|name=World|bold=yes}}

Transcluding a help page:

{{:Help:Formatting}}

Tools

[edit]

See also

[edit]

This help page explains transclusion for editors. For troubleshooting specific templates, consult the template’s /doc and talk pages.