Jump to content

Help:Transclusion: Difference between revisions

From the Vrienden Universe, a fictional wiki
wiki>Butwhatdoiknow
top: copy edit > "every" to "each"
 
m 1 revision imported
(No difference)

Revision as of 01:53, 1 February 2026

Template:Pp-vandalism Template:Pp-move-indef

Template:Redirect Template:Broader Template:Information page

In Wikipedia, transclusion is the inclusion of content from a source page, often a template, into the content of a target page. This happens each time the target page is viewed. Transclusion differs from substitution, which copies the source page into the target page once and permanently.

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.Template:Refn

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:

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.Template:Refn 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.Template:Refn

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:Fake link) 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.Template:Refn

Wikipedia is structured using namespaces, which organize pages based on their function. For example, a page titled Template:Xtn belongs to the Wikipedia namespace, with Wikipedia: as its namespace and Tips as its pagename. However, articles in the Main namespace, such as Template:Xtn, 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 Template:Char (e.g., <syntaxhighlight lang="wikitext" inline="">Potato</syntaxhighlight>).

Examples

blue lightbulb Summary: <syntaxhighlight lang="wikitext" inline>Template:Pagename</syntaxhighlight> or <syntaxhighlight lang="wikitext" inline>Template:Pagename</syntaxhighlight> will transclude the content of Template:Xtn.
<syntaxhighlight lang="wikitext" inline>Pagename</syntaxhighlight> will transclude the mainspace article titled Template:Xtn.
<syntaxhighlight lang="wikitext" inline>Template:Namespace:Pagename</syntaxhighlight> transcludes a page in the defined namespace, such as Template:Xtn.
  • 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 Template:Xtn 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 to Wikipedia:.
  • 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 Template:Xtn.
  • 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:Xtn.

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:

For example, to transclude Template:Xtn, 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:Xtn 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:Xtn that accepts three parameters, the general format would be:

<syntaxhighlight lang="wikitext" inline="">Template:Pagename</syntaxhighlight>

Template:Shortcut 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.Template:Refn

For example, using the Template:Xtn with two unnamed parameters and one named parameter:

Template:Y <syntaxhighlight lang="wikitext" inline="">