Help:Transclusion

Help:Transclusion on Wikipedia
An illustration of the scope of transclusion.

Transclusion means the inclusion of the content of one document in another document by reference. In Saintapedia, it refers to a function of the MediaWiki software that allows the content of one page to be included in the content of another page, by placing a reference to the source page in the wikitext of the target page. A page that is intended to be transcluded into other pages is called a template. Changes made to a template are automatically reflected on all pages into which that template has been transcluded.

In addition to templates, it is possible to share portions of a page using Labeled Section Transclusion.

Templates

Templates are the main way in which transclusion occurs on Saintapedia, often with the use of Navboxes and Infoboxes.

Noinclude, includeonly, and onlyinclude

The info is from Help:Templates#Noinclude,_includeonly,_and_onlyinclude

abc  def 

Labeled Section Transclusion

Labeled Section Transclusion allows the transclusion of a specific section of a page rather than an entire page.

The Labeled Section Transclusion extension provides two primary mechanisms which needed to be done in Enhanced editor (not VisualEditor) for transcluding information:

  1. Using section section heads. Examples
    • {{#lsth:YouTube|Embedding videos}} will transclude the "Embedding videos" section.
    • {{#lsth:YouTube}} will transclude the introduction (the info above the first section head).
  2. Adding section tags to relevant parts of a document. Example:
    • <section begin=givethesectionaname /> what do you want to include <section end=givethesectionaname /> in the source page documents what is to be transcluded
    • {{#lst:articleX|givethesectionaname}} would then be used to call that section and transclude it to the location of your choice.

The lead Gardener recommends using the section head approach to help keep the edit window as clean as possible on all related pages. This approach is not without drawbacks, namely if the section head changes, the transclusion will break, but we feel this is the most pragmatic approach.

Example: Test Transclude the intro of YouTube}

{{#lsth:YouTube}}
The Pontificate of John Paul II begins

YouTube is a website designed for sharing videos. Users can upload, view, rate, share, add to playlists, report, comment on videos, and subscribe to other users.

YouTube's algorithm suggests videos based on user behavior, watch history, and what's trending.

Official Site - youtube.com


How Transclusion Works

To transclude any source page (within a single MediaWiki project, such as en:Wikipedia), use the following code in the target page:

{{SOURCEPAGE}}

Any time you write the code ({{SOURCEPAGE}}) in a target page, you are telling Wikipedia software to put the entire content of SOURCEPAGE in the target page.

In the example below, look at target page A and SOURCEPAGE B.

If B is transcluded in A, Wikipedia software will include in that specific place not the code ({{B}}) itself but the content of source page B (which is just the word foo).

The top row shows how target pages A, P, and Q will look with the changes in code seen in the bottom row to transclude source page B. Note the position of the code in each example target page.

The source page content, foo, will not be highlighted or boxed on the target page. (Foo is in a light blue box here for ease of illustration and understanding.)


Transclusion creates a "live" link between a source page and the target page(s) where the source page's contents appear. This means that when you edit a source page, you will be updating its content across all the target pages that include it. Let's say you create a source page in Wikipedia with the address, date, and time of a local Wikimedia event that you want to invite 50 local editors to. Next, you transclude the invitation source page onto your talk page as well as the talk pages of the other 50 editors. A week later you discover the place for the event must be moved. You would then update the source page, and the new address will automatically appear on all the other attendees' talk pages. You could also tell the editors to invite people you may have missed. They could then simply transclude the invitation source page into other editors' talk pages themselves.

Remember to be extremely careful about editing any source page, especially if it contains transclusions from other source pages. Breaking existing transclusions in a source page is called breakage. Please avoid breakage(s) because not only the larger source page you are editing and all the target pages that include it will be affected. So will both the already embedded (now broken) source page that was used to add content to the larger source page, as well as every target page where the embedded source page was transcluded.

See also