Help:Transclusion
![]() | This is an information page. It is not an encyclopedic article, nor one of Wikipedia's policies or guidelines; rather, its purpose is to explain certain aspects of Wikipedia's norms, customs, technicalities, or practices. It may reflect differing levels of consensus and vetting. |
Transclusion refers to the inclusion of the content from one document within another document by reference. In Wikipedia, transclusion means the MediaWiki software retrieving the content from a source page, often a template, and incorporating it into the content of a target page.
Similar to creating a wikilink using double square brackets (<syntaxhighlight lang="wikitext" inline="">Pagename</syntaxhighlight>
), a page can be transcluded as a template by enclosing its title in double curly braces or double curly brackets: <syntaxhighlight lang="wikitext" inline="">Template:Namespace:Pagename</syntaxhighlight>. Any changes made to the source page, or template, are automatically reflected on all pages that include the transcluded content.<ref group="lower-alpha">A purge may occasionally be necessary to refresh target pages, ensuring they retrieve and display the latest content from the template or source page. This forces the MediaWiki software to clear the cached version of the page and reload it with the most up-to-date transcluded content.</ref>
If no namespace is specified, it is assumed to be in the Template namespace. To refer to a page in the Main article namespace, it is necessary to prefix it with a colon (:
). For example:
- <syntaxhighlight lang="wikitext" inline="">Template:Pagename</syntaxhighlight> is the same as <syntaxhighlight lang="wikitext" inline="">Template:Pagename</syntaxhighlight>
- <syntaxhighlight lang="wikitext" inline="">Template:Stochastic processes</syntaxhighlight> will transclude from the page Template:Stochastic processes
- <syntaxhighlight lang="wikitext" inline="">Stochastic processes</syntaxhighlight> will transclude from the page Stochastic processes (an article, in the Main namespace)
- <syntaxhighlight lang="wikitext" inline="">{{Wikipedia:Assume good faith}}</syntaxhighlight> will transclude from the page Wikipedia:Assume good faith
Transclusion and what content it includes or excludes can be modified by using the invisible wikitext tags <noinclude>
, <onlyinclude>
, <includeonly>
, and <section>
on the source page, as further outlined in § Transclusion markup.<ref group="lower-alpha">Transclusion relies on functions that parse the source page, meaning that the appropriate wikitext markup must be present on the source page for it to correctly include or exclude content. The specific tags used for this purpose determine how the content will be transcluded into the target page. Properly implementing these tags allows editors to control the visibility of certain parts of the content based on the needs of the target page.</ref> The first three tags enable § Partial transclusion, as opposed to the default behavior of double curly braces, which will transclude the entire source page's content. For § Selective transclusion, the <includeonly>
or <section>
tags can be used and sections of the source page named, then using parser functions the template can be called with the section name as a parameter: <syntaxhighlight lang="wikitext" inline="">{{#section:Pagename|Sectionname}}</syntaxhighlight>.
Transclusion events occur each time the target page is loaded and the template is rendered. A related event is Substitution, where a template call is replaced with its transcluded source content at the time it is invoked in a one-time inclusion of the content. Unlike transclusion, which continuously updates the target page with changes from the source, substitution results in a one-time inclusion of the content, meaning that subsequent updates to the source content will not be reflected in the target page. For example, a template call for <syntaxhighlight lang="wikitext" inline="">Template:Pagename</syntaxhighlight> with the <syntaxhighlight lang="wikitext" inline="">subst:</syntaxhighlight> prefix results in the substitution template call <syntaxhighlight lang="wikitext" inline="">{{subst:Pagename}}</syntaxhighlight>. When invoked, this template is replaced, also referred to as substituted, with the actual wikitext of the source page at the time of the call, thereby making it a permanent part of the target page.<ref group="lower-alpha">In simpler terms, the page is published or saved, and any future changes to the source page will not affect this substituted content.</ref>
It is possible to transclude content from Wikidata into Wikipedia articles or other wikis.
How transclusion works
To transclude content from a source page within a single MediaWiki project (such as English Wikipedia) onto a target page, use {{SOURCEPAGE}}
in the target page's code.
Whenever {{SOURCEPAGE}}
is included on a target page, the WikiMedia software retrieves and embedes the entire content of SOURCEPAGE
(i.e., Template:SOURCEPAGE) at that location on the target page.
Example
Consider an example, complemented by the illustration below, with target pages A, P, and Q, and source page B.
If source page B is transcluded into A, the content from B (for instance, the word "foo") will appear in place of the {{B}}
code in page A. When transcluded, this content is not highlighted or boxed on the target page – it is integrated directly into the page's text (highlighted here only for illustration).
How it works
Transclusion creates a 'live' link between a source page and all target pages where its content is transcluded to and used. Editing the source page automatically updates its content on all target pages that include it.
For example, if you create a source page with details about a Wikimedia event and transclude it onto the talk pages of 50 editors you wish to invite, any updates you make to the source page (such as changing the event location) will immediately reflect on all 50 talk pages.
Edit source pages with caution
Edits to a source page can impact all target pages using it. If a source page also contains its own transclusions from other source pages, avoid changes that may break these links, as this would affect the source page you are editing and all target pages that transclude it. This is known as 'breakage', and it is best to ensure any updates maintain the integrity of transcluded content across all pages. For example, Main Page is a large page that transcludes its content from multiple embed source pages such as Wikipedia:Today's featured list.
Transclusion syntax
The general syntax for transclusion on Wikipedia follows the format <syntaxhighlight lang="wikitext" inline="">Template:Namespace:Pagename</syntaxhighlight>, where Namespace:Pagename
specifies the title of a Wikipedia page.
Similar to creating a wikilink using double square brackets (<syntaxhighlight lang="wikitext" inline="">Pagename</syntaxhighlight>
), a page can be transcluded as a template by enclosing its title in double curly braces: <syntaxhighlight lang="wikitext" inline="">Template:Namespace:Pagename</syntaxhighlight>. Any changes made to the source page, or template, are automatically reflected on all pages that include the transcluded content.<ref group="lower-alpha">A purge may occasionally be necessary to refresh target pages, ensuring they retrieve and display the latest content from the template or source page. This forces the MediaWiki software to clear the cached version of the page and reload it with the most up-to-date transcluded content.</ref>
Wikipedia is structured using namespaces, which organize pages based on their function. For example, a page titled Wikipedia:Tips belongs to the Wikipedia namespace, with Wikipedia:
as its namespace and Tips
as its pagename. However, articles in the Main namespace, such as Potato, do not require a namespace prefix when linked using <syntaxhighlight lang="wikitext" inline="">Potato</syntaxhighlight>
, as Wikipedia assumes any wikilink without a specified namespace belongs to the Article namespace.
When transcluding pages, if no namespace is specified, Wikipedia defaults to the Template namespace. To reference a page in the Article namespace within transclusion syntax, it must be explicitly prefixed with a colon : (e.g., <syntaxhighlight lang="wikitext" inline="">Potato</syntaxhighlight>).
Examples
![]() |
using <syntaxhighlight lang="wikitext" inline>Template:Pagename</syntaxhighlight> or <syntaxhighlight lang="wikitext" inline>Template:Pagename</syntaxhighlight> will transclude the content of Template:Pagename. Using <syntaxhighlight lang="wikitext" inline>Pagename</syntaxhighlight> instead will transclude the mainspace article titled Pagename. Including <syntaxhighlight lang="wikitext" inline>Template:Namespace:Pagename</syntaxhighlight> transcludes a page in the defined namespace, such as Help:Pagename. |
- Specifying namespace: <syntaxhighlight lang="wikitext" inline>Template:Namespace:Pagename</syntaxhighlight> will transclude the page titled <syntaxhighlight lang="wikitext" inline>Namespace:Pagename</syntaxhighlight>. For example, if a page has the wikitext <syntaxhighlight lang="wikitext" inline>{{Wikipedia:Notability}}</syntaxhighlight> in it, it will transclude the page Wikipedia:Notability into it. Please note that <syntaxhighlight lang="wikitext" inline>Template:WP:Notability</syntaxhighlight> would do exactly the same thing, as
WP:
is a namespace alias, which is automatically translated by the Wikipedia servers toWikipedia:
.
- Calling from the Article namespace: If the namespace is omitted, but the colon is included, like <syntaxhighlight lang="wikitext" inline>Pagename</syntaxhighlight>, the mainspace article
Pagename
will be transcluded. For example, <syntaxhighlight lang="wikitext" inline>Notability</syntaxhighlight> will transclude the article [[Notability|Notability]].
- Template namespace: If both namespace and colon are omitted, like <syntaxhighlight lang="wikitext" inline>Template:Pagename</syntaxhighlight>, the
Template:Pagename
will be transcluded. For example <syntaxhighlight lang="wikitext" inline>Template:Notability</syntaxhighlight>, and also <syntaxhighlight lang="wikitext" inline>Template:Notability</syntaxhighlight>, will both transclude the [[Template:Notability|Template:Notability]].
Additionally, specific § Template parameters and § Transclusion modifiers allow parameters to be passed to templates, alter how transclusion occurs, and therefore the output customized. This is explained in more detail below.
Subpages
Subpages, identifiable by a /
prefixed in their page names, are pages related to a 'parent' page (e.g., Namespace:Pagename/Subpagename
is a subpage of Namespace:Pagename
). This feature is disabled in the Main, File, and MediaWiki namespaces, but not on their corresponding talk namespaces.
To transclude subpages:
- In general, use <syntaxhighlight lang="wikitext" inline>Template:Namespace:Pagename/Subpagename</syntaxhighlight>. With exception:
- On the parent page of a subpage, the more specific general syntax mentioned above can be used or simply <syntaxhighlight lang="wikitext" inline>Help:Transclusion/Subpagename</syntaxhighlight>.
- For a template namespace page, it is either the general syntax or <syntaxhighlight lang="wikitext" inline>Template:Pagename/Subpagename</syntaxhighlight>.
- Article subpages are disabled on this wiki, but would otherwise be <syntaxhighlight lang="wikitext" inline>Pagename/Subpagename</syntaxhighlight>.
- Alternatively, you can also use § Template parameters and § Transclusion modifiers.
For example, to transclude Template:Like/doc, you could use <syntaxhighlight lang="wikitext" inline>Template:Like/doc</syntaxhighlight> or <syntaxhighlight lang="wikitext" inline>Template:Like/doc</syntaxhighlight>. Note that subpage names are case sensitive, and <syntaxhighlight lang="wikitext" inline>Template:Like/Doc</syntaxhighlight> would lead to a different page.
Template parameters
The most common use of transclusion on Wikipedia is for templates. Templates are specially designed pages intended to be included in other pages using either transclusion or substitution. The standard syntax for transcluding a template titled Template:Pagename is <syntaxhighlight lang="wikitext" inline="">Template:Pagename</syntaxhighlight>.
Additionally, many templates support parameters, which are variables that allow templates to function in different ways by passing specific values, also termed arguments. Templates may have no parameters, use a fixed number of parameters, or support a variable number of parameters. The number of parameters a template can accept ranges from one to multiple, depending on its design.
The exact syntax for using parameters varies by template. However, for a hypothetical template titled Template:Pagename that accepts three parameters, the general format would be:
<syntaxhighlight lang="wikitext" inline="">Template:Pagename</syntaxhighlight>
Where each parameter in a template can be substituted with either a value
or a |parameter name=value
format when used in practice. Notice that each parameter is separated by a vertical bar (|
). Parameters that take the form value
are called unnamed or positional parameters, while those in the form |parameter name=value
are known as named parameters. With unnamed parameters, the first, second, and third parameters correspond to |1=
, |2=
, |3=
, respectively, etc., in template documentation. Unnamed parameters must be provided in the correct order and are best placed before named parameters.<ref group="lower-alpha">Otherwise using value
on its own will not work, and the unnamed parameters must be called using their 'names', such as |1=value
, if named parameters precede them.</ref>
For example, using the Template:Collapse top with two unnamed parameters and one named parameter:
<syntaxhighlight lang="wikitext" inline="">
This is the title text
|
---|