Help:Transclusion/How Transclusion Works: Difference between revisions

Content deleted Content added
m Reverted edits by Niebieskidlugopis (talk) to last version by IronGargoyle
Reverted 1 edit by 2600:387:15:3931:0:0:0:7 (talk): Unexplained deletion, left the sentence incomplete
 
(27 intermediate revisions by 19 users not shown)
Line 1:
To '''transclude''' anycontent from a '''source''' page (within a single MediaWiki project, (such as en:English Wikipedia), includeonto thea following''target'' page, use <code><nowiki>{{SOURCEPAGE}}</nowiki></code> in the '''target''' page:'s code.
{{navbar|Wikipedia:Transclusion/How Transclusion Works|plain=1}}
 
Whenever <code><nowiki>{{SOURCEPAGE}}</nowiki></code> is included on a target page, the WikiMedia software retrieves and embedes the entire content of <code>SOURCEPAGE</code> (i.e., {{Fake link|Template:SOURCEPAGE}}) at that ___location on the target page.
To '''transclude''' any '''source''' page (within a single MediaWiki project, such as en:Wikipedia), include the following code in the '''target''' page:
 
=== Example ===
<code><nowiki>{{SOMEPAGE}}</nowiki></code>
Consider an example, complemented by the illustration below, with target pages '''A''', '''P''', and '''Q''', and source page '''B'''.
 
WheneverIf the targetsource page '''AB''' withis thistranscluded codeinto is rendered'''A''', the engine willcontent includefrom ''in that place'B''' not(for instance, the codeword itself,"foo") butwill theappear entirein contentplace of the source<code><nowiki>{{B}}</nowiki></code> code in page '''BA'''. When transcluded, SOMEPAGE.this content Theis topnot rowhighlighted showsor whatboxed on the target page renders as,it whileis theintegrated bottomdirectly row showsinto the code.page's Note: foo will not betext (highlighted norhere boxedonly onfor theillustration).<div targetstyle="margipadding: page0.5em;">[[File:Transclusion-multiple-foo.svg]]</div>
 
=== How it works ===
<div style="{{divstylenone}}">
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.
[[File:Transclusion-multiple-foo.svg]]
</div>
 
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.
For example, you might decide to place a welcome message on every newcomer's talk page.
 
=== Edit source pages with caution ===
Transclusion creates a "live" link between the template page and the target page(s) upon which the template's contents should appear. When the template is edited, the rendering of that template on the target pages is updated as well. For example, you create a (template) page in Wikipedia with your home mailing address and then transclude that template not only on your page, but all your friends' pages, too. Later, after moving to a new house, you then update your address template and the ''new'' address will automatically appear on all your friends' pages.
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]].