Wavelength (talk | contribs) →See also: adding 1 internal link: * Wikipedia:WikiProject Modular Articles |
|||
Line 70:
* [[MediaZilla:4547|Request for template transclusion from Commons]] (interwiki templates, etc.)
* [[Wikipedia:Substitution]] (the opposite of transclusion)
* [[Wikipedia:WikiProject Modular Articles]]
[[Category:Wikipedia editing]]
|
Revision as of 02:08, 13 September 2010
Transclusion is the inclusion of the content of a document into another document by reference. In the Wikipedian context, it is the use of the template functionality of MediaWiki to include the same content in multiple documents without having to edit those documents separately. Template transclusion is the common way to use template messages, and is implemented by using a template tag, with this form below:
{{Template name}}
Occasionally one may want to use a template, but for one reason or another may not want to use transclusion. The automatic one-time copying of a template's code/text to the location of a template tag is called template substitution or subclusion (substitution + transclusion). To subclude a template's code/text, the template tag is modified from the standard transclusion tag to a substitution tag, simply by adding subst:
, creating a tag with the form:
{{subst:Template name}}
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.
Etymology
Ted Nelson coined the term in his 1982 book, Literary Machines. Ted Nelson is also the inventor of the terms "hypertext" and "hypermedia".
Partial transclusion
By using "noinclude", "onlyinclude" and "includeonly" markup, it is possible to transclude part of a page rather than all of it. Such partial transclusions can also be achieved by transcluding from other pages such as subpages. It is often useful not to transclude some information, such as template documentation.
For an example of how this technique can be applied to simplify the creation of summary articles, see this revision of Pathology, which consisted of a collection of transcluded lead paragraphs from several main articles.
Markup
There are three pairs of tags that can be used in wikitext to control how transclusion affects elements of a template or article. They determine whether or not wikitext renders, either in its own article, which we will call "here", or in another article where it is transcluded, which we will call "there".
- <noinclude> this content will not be rendered there </noinclude> . These tags have no effect here.
- <includeonly> this content will render only there, and will not render here </includeonly> (like invisible ink made visible by means of transclusion).
- <onlyinclude> this content will render here and will render there </onlyinclude> but the rest of the article will be excluded from rendering there.
There can be several such section elements. Also, they can be nested. All possible renderings are achievable. For example, to render there one or more sections of the page here use <onlyinclude> tags. To append text there, wrap the addition in <includeonly> tags above, within, or below the section. To omit portions of the section, nest <noinclude> tags within it.
As a memory aid insert the phrase in transclusion between the two words to get "noInTransclusionInclude", "includeInTransclusionOnly" and "onlyInTransclusionInclude".
Subpages
One can cut and paste the text to be transcluded into a subpage, then use the name of the subpage in the transclusion template. This approach can only be used with subpages from User, Talk or Wikipedia pages; currently, subpages cannot be created from main article pages.
Example: you want to discuss the deletion and redirecting of Pussycat to Cat. First, create the subpage Talk:Pussycat/Let's delete Pussycat!, write your comment into it, then transclude it in Talk:Pussycat and Talk:Cat using the template {{Talk:Pussycat/Let's delete Pussycat!}}. Comments posted in either talk pages will be shown in both.
Special pages
Some pages on Special:Specialpages can be transcluded, such as Special:Allpages, Special:Prefixindex, Special:Newfiles, Special:Newpages, Special:Recentchanges and Special:Recentchangeslinked.
Samples:
- {{Special:Allpages/General}} – a list of pages starting at "General"
- {{Special:Prefixindex/General}} – a list of pages with prefix "General"
- {{Special:Newfiles/4}} – a gallery of the four most recently uploaded files
- {{Special:Newpages/5}} – a list of the five most recently created pages
- {{Special:Recentchanges/5}} – the five most recent changes
- {{Special:Recentchangeslinked/General}} – recent changes to the pages linked from "General"
Except for Special:Recentchangeslinked, the slash and the word/number after the slash can be omitted, giving a list of pages without a specific starting point, or a list of the default length.
Pages related to MediaWiki transclusion
- m:Help:A simple composite example
- Wikipedia:MediaWiki namespace
- m:Help:Variable
- Wikipedia talk:Template namespace#transcluding prose
Templates
See also
- Request for template transclusion from Commons (interwiki templates, etc.)
- Wikipedia:Substitution (the opposite of transclusion)
- Wikipedia:WikiProject Modular Articles