Help:Transclusion/How Transclusion Works: Difference between revisions

Content deleted Content added
deleted use case example, which used unnecessary jargon and seemed redundant with the examples farther down, which of course can be changed if need be
Tags: Mobile edit Mobile web edit Advanced mobile edit
Reverted 1 edit by 2600:387:15:3931:0:0:0:7 (talk): Unexplained deletion, left the sentence incomplete
 
(4 intermediate revisions by 3 users not shown)
Line 1:
To '''transclude''' anycontent from a '''source''' page (within a single MediaWiki project, (such as en:English Wikipedia), useonto thea following''target'' page, use <code><nowiki>{{SOURCEPAGE}}</nowiki></code> in the '''target''' page:'s code.
 
AnyWhenever time you write the code (<code><nowiki>{{SOURCEPAGE}}</nowiki></code>) inis included on a target page, you are tellingthe WikipediaWikiMedia software toretrieves putand embedes the entire content of <code><nowiki>SOURCEPAGE</nowiki></code> in(i.e., {{Fake link|Template:SOURCEPAGE}}) at that ___location on the target page.
<code><nowiki>{{SOURCEPAGE}}</nowiki></code>
 
=== Example ===
Any time you write the code (<code><nowiki>{{SOURCEPAGE}}</nowiki></code>) in a target page, you are telling Wikipedia software to put the entire content of <code><nowiki>SOURCEPAGE</nowiki></code> in the target page.
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 <code><nowiki>{{B}}</nowiki></code> 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).<div style="margipadding: 0.5em;">[[File:Transclusion-multiple-foo.svg]]</div>
In the example below, look at target page '''A''' and <code><nowiki>SOURCEPAGE</nowiki></code> '''B'''.
 
=== How it works ===
If '''B''' is transcluded in '''A''', Wikipedia software will include ''in that specific place'' not the code (<code><nowiki>{{B}}</nowiki></code>) itself but the content of source page '''B''' (which is just the word ''foo'').
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.
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.
 
=== Edit source pages with caution ===
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.)
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]].
 
<div style="margipadding: 0.5em;">[[File:Transclusion-multiple-foo.svg]]</div>
</br>
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.