Help:Transclusion/How Transclusion Works: Difference between revisions

Content deleted Content added
post move cleanup
Tag: Reverted
expanded content to be less verbose in order to improve clarity
Tag: Reverted
Line 2:
To '''transclude''' any '''source''' page (within a single MediaWiki project, such as en:Wikipedia), include the following code in the '''target''' page:
 
<code><nowiki>{{SOMEPAGESOURCEPAGE}}</nowiki></code>
 
Whenever thea target page '''A''' with this code (<code><nowiki>{{SOURCEPAGE}}</nowiki></code>) is rendered, the engine will include ''in that place'' not the code itself, but the entire content of the source page '''B''', SOMEPAGE. The top row shows what the target page renders as, while the bottom row shows the <code.><nowiki>SOURCEPAGE</nowiki></code> Note: foo will not be highlighted nor boxed onin the target page.
 
In the example below, let the target page be '''A''' and <code><nowiki>SOURCEPAGE</nowiki></code> be '''B'''. If <code><nowiki>{{B}}</nowiki></code> is rendered, 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 one word, foo).
 
The top row shows what the target page renders as, while the bottom row shows the code. Note: foo will not be highlighted nor boxed on the target page.
 
<div style="margipadding: 0.5em;">[[File:Transclusion-multiple-foo.svg]]</div>
 
ForA example,typical youuse mightcase decidefor transclusion would be if you wanted to place athe same welcome message on everymultiple newcomer's talk pagepages.
 
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. ForLet's example,say 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.
 
There are further simple examples at [[mw:Transclusion]].
 
On the other hand, breakingBreaking existing transclusions in a template is called '''breakage'''. It is to be avoided if possible, as the breakage will ripple through every target page in which the template (source) page was transcluded.