Help:Transclusion/How Transclusion Works: Difference between revisions

Content deleted Content added
m Reverted edits by 2806:106E:20:40BD:5CD6:88EE:EB27:E2E8 (talk): nonconstructive edits (HG) (3.4.10)
rewrote to make it understandable for laypeople; in the final paragraph, I may have been too bold
Tags: Mobile edit Mobile web edit Advanced mobile edit
Line 1:
To '''transclude''' any '''source''' page (within a single MediaWiki project, such as en:Wikipedia), includeuse the following code in the '''target''' page:
 
<code><nowiki>{{SOURCEPAGE}}</nowiki></code>
 
WheneverAny atime targetyou pagewrite with thisthe code (<code><nowiki>{{SOURCEPAGE}}</nowiki></code>) isin rendereda target page, theyou are telling Wikipedia enginesoftware willto includeput the entire content of <code><nowiki>SOURCEPAGE</nowiki></code> in the target page.
 
In the example below, letlook us start withat target page '''A''' and <code><nowiki>SOURCEPAGE</nowiki></code> '''B'''. <br />
If '''B''' is transcluded in '''A''', then the engine will include ''in that place'' not the code (<code><nowiki>{{B}}</nowiki></code>) itself but the content of source page '''B''' (which consists of only one word, foo).
 
If '''B''' is transcluded in '''A''', thenWikipedia the enginesoftware will include ''in that specific place'' not the code (<code><nowiki>{{B}}</nowiki></code>) itself but the content of source page '''B''' (which consistsis ofjust only onethe word, ''foo'').
The top row shows how the target page '''A''' renders, while the bottom row shows the code required to transclude the source page within the target page. Note that the position of the code determines how each of the target pages '''A''', '''P''', and '''Q''' will render.
 
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 nor boxed on the target page.
 
The source page content, ''foo'', will not be highlighted noror boxed on the target page. (''Foo'' is in a light blue box here for ease of illustration and understanding.)
 
<div style="margipadding: 0.5em;">[[File:Transclusion-multiple-foo.svg]]</div>
Line 16 ⟶ 17:
A typical use case for transclusion would be if you wanted to place the same welcome message on multiple newcomer talk pages.
 
Transclusion creates a "live" link between thea templatesource page and the target page(s) upon whichwhere the templatesource page's contents should appear. WhenThis themeans templatethat iswhen editedyou edit a source page, theyou renderingwill ofbe thatupdating templateits oncontent across all the target pages isthat updatedinclude as wellit. Let's say you create a (template)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 thatthe templateinvitation onsource page onto your talk page, andas alsowell onas the talk pages of allthe localother 50 editors to be invited. A week later, theyou eventdiscover isthe movedplace tofor athe slightlyevent largermust placebe moved. You would then update the addresssource templatepage, and the ''revised''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 templatesource page is called '''breakage'''. ItPlease isavoid tobreakage(s) bebecause avoidednot ifonly possible,the aslarger source page you are editing and all the breaktarget pages that include it will propagatebe throughaffected. 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 in whichwhere the templateembedded (source) page was transcluded.