Difference between revisions of "Help:Transclusion"
(Created page with "{{NHP}} '''Transclusion''' is generally the inclusion of the content of a document into another document by reference. In a Wikipedia context, it is the use of the [[w:Wikip...") |
m (removed dead links) |
||
(14 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
{{NHP}} | {{NHP}} | ||
− | '''[[Transclusion]]''' is generally the inclusion of the content of a document into another document by reference. In a Wikipedia context, it is the use of the [[w:Wikipedia:Template messages|template functionality]] of | + | '''[[Transclusion]]''' is generally the inclusion of the content of a document into another document by reference. In a Wikipedia context, it is the use of the [[w:Wikipedia:Template messages|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 the form: |
:<code><nowiki>{{template name}}</nowiki></code> | :<code><nowiki>{{template name}}</nowiki></code> | ||
Line 6: | Line 6: | ||
==How transclusion works== | ==How transclusion works== | ||
− | |||
− | |||
− | |||
− | |||
<div class="boilerplate metadata" id="Template syntax" style="background-color: #CCFFCC; border: 1px solid #009900; margin: 0.5em; padding: 0.5em; float: right; width: 35%; "><center><b>Template syntax</b></center> | <div class="boilerplate metadata" id="Template syntax" style="background-color: #CCFFCC; border: 1px solid #009900; margin: 0.5em; padding: 0.5em; float: right; width: 35%; "><center><b>Template syntax</b></center> | ||
Line 25: | Line 21: | ||
Whenever the target page '''A''' with this code is rendered, the engine will include ''in that place'' not the code itself, but the entire content of the source page '''B''', SOMEPAGE. | Whenever the target page '''A''' with this code is rendered, the engine will include ''in that place'' not the code itself, but the entire content of the source page '''B''', SOMEPAGE. | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
{{clear}} | {{clear}} | ||
Line 40: | Line 29: | ||
{{clear}} | {{clear}} | ||
+ | |||
== Etymology == | == Etymology == | ||
[[:en:Ted Nelson|Ted Nelson]] coined the term "[[transclusion]]," as well as "[[w:hypertext|hypertext]]" and "[[w:hypermedia|hypermedia]]", in his 1982 book, ''[[w:Literary Machines|Literary Machines]]''. | [[:en:Ted Nelson|Ted Nelson]] coined the term "[[transclusion]]," as well as "[[w:hypertext|hypertext]]" and "[[w:hypermedia|hypermedia]]", in his 1982 book, ''[[w:Literary Machines|Literary Machines]]''. | ||
Line 46: | Line 36: | ||
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. | 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 [ | + | For an example of how this technique can be applied to simplify the creation of [http://en.wikipedia.org/wiki/WP:SS summary articles], see [http://en.wikipedia.org/w/index.php?title=Pathology&oldid=301684595], which consisted of a collection of transcluded [[w:WP:LEAD|lead paragraphs]] from several main articles. |
===Transclusion markup=== | ===Transclusion markup=== | ||
− | * '''noinclude'''. The markup | + | * '''noinclude'''. The markup <code><noinclude></noinclude></code> means that the text between the tags will not be transcluded onto another page, but will only appear on the page itself. This is useful for documentation. |
− | * '''includeonly'''. The markup | + | * '''includeonly'''. The markup <code><includeonly></includeonly></code> means that the text between the tags will only be used when the page is transcluded onto another page, and will not appear on the page itself. This can be useful, for example, for adding categories to pages transcluding a template, without adding the template itself to these categories. |
− | * '''onlyinclude'''. The markup | + | * '''onlyinclude'''. The markup <code><onlyinclude></onlyinclude></code> indicates that only text surrounded by "onlyinclude" markup should be transcluded onto another page. This is the most subtle of the partial transclusion tags because it often overrules the others. If there is at least one pair of "onlyinclude" tags on a page, then whenever this page is transcluded, it is ''only'' the material within the "onlyinclude" tags which gets transcluded. There can be several such sections, and within each such section, some material might be further excluded by "noinclude" tags, and might also be surrounded by "includeonly" tags so that it does not appear on the original page itself. But material outside the "onlyinclude" tags will be ignored when the page is transcluded onto another page. This can be useful, for example, to repeat a small part of one page on a second one: just surround the small part by onlyinclude tags, and transclude it onto the second page. Note that unlike {{Tag|noinclude|open}} and {{Tag|includeonly|open}}, {{Tag|onlyinclude|open}} will take precedence over enclosing {{Tag|nowiki|open}} tags. In other words, {{Tag|nowiki|content={{Tag|onlyinclude|content=My content}}}} produces only "My content" when transcluded. |
===Subpages=== | ===Subpages=== | ||
Line 60: | Line 50: | ||
===Special pages=== | ===Special pages=== | ||
− | :''See also:[[ | + | :''See also:[[Wikipedia:Special pages#Miscellaneous]]'' |
Some pages on [[Special:Specialpages]] can be transcluded, e.g. [[Special:Newpages]] | Some pages on [[Special:Specialpages]] can be transcluded, e.g. [[Special:Newpages]] | ||
Sample: <nowiki>{{Special:Newpages/3}}</nowiki> gives 3 new pages. | Sample: <nowiki>{{Special:Newpages/3}}</nowiki> gives 3 new pages. | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
==Templates== | ==Templates== | ||
− | * [[Help:Template]] | + | * [[Help:Templates|Help:Template]] |
− | * [[ | + | * [[Wikipedia:Wikipedia:Template namespace]] |
− | * [[ | + | * [[Wikipedia:Wikipedia:Template limits]] |
== See also == | == See also == | ||
− | * [[ | + | * [[Wikipedia:Wikipedia:Substitution]] (the opposite of transclusion) |
− | |||
− | [[Category: | + | <!--[[Category:Help|{{PAGENAME}}]]--> |
− |
Latest revision as of 18:53, 28 October 2011
![]() |
This page is under construction or some major changes are in progress. |
Transclusion is generally the inclusion of the content of a document into another document by reference. In a Wikipedia 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 the form:
{{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}}
.
How transclusion works
To transclude any source page (within a single MediaWiki project, such as en:Wikipedia) within another target page, include the following code:
{{SOMEPAGE}}
Whenever the target page A with this code is rendered, the engine will include in that place not the code itself, but the entire content of the source page B, SOMEPAGE.
For example, you might decide to place a welcome message on every newcomer's Talk Page. Transclusion creates a "live" link between the template-page and the target-page(s) upon which the message should appear. When the template is edited, all the target-pages are edited too.
For example, you might decide to create a (template) page with your mailing address and include that template on not only your page, but all your friends' pages, too. When you move your television and couch to another apartment, you will change your address template, and automatically, that new information will appear on all your friends' pages.
Etymology
Ted Nelson coined the term "transclusion," as well as "hypertext" and "hypermedia", in his 1982 book, Literary Machines.
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 [1], which consisted of a collection of transcluded lead paragraphs from several main articles.
Transclusion markup
- noinclude. The markup
<noinclude></noinclude>
means that the text between the tags will not be transcluded onto another page, but will only appear on the page itself. This is useful for documentation. - includeonly. The markup
<includeonly></includeonly>
means that the text between the tags will only be used when the page is transcluded onto another page, and will not appear on the page itself. This can be useful, for example, for adding categories to pages transcluding a template, without adding the template itself to these categories. - onlyinclude. The markup
<onlyinclude></onlyinclude>
indicates that only text surrounded by "onlyinclude" markup should be transcluded onto another page. This is the most subtle of the partial transclusion tags because it often overrules the others. If there is at least one pair of "onlyinclude" tags on a page, then whenever this page is transcluded, it is only the material within the "onlyinclude" tags which gets transcluded. There can be several such sections, and within each such section, some material might be further excluded by "noinclude" tags, and might also be surrounded by "includeonly" tags so that it does not appear on the original page itself. But material outside the "onlyinclude" tags will be ignored when the page is transcluded onto another page. This can be useful, for example, to repeat a small part of one page on a second one: just surround the small part by onlyinclude tags, and transclude it onto the second page. Note that unlike Template:Tag and Template:Tag, Template:Tag will take precedence over enclosing Template:Tag tags. In other words, Template:Tag produces only "My content" when transcluded.
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 where subpages are enabled; for example, on the English Wikipedia, subpages can only be used 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 page will be shown in both.
Special pages
Some pages on Special:Specialpages can be transcluded, e.g. Special:Newpages
Sample: {{Special:Newpages/3}} gives 3 new pages.
Templates
See also
- Wikipedia:Wikipedia:Substitution (the opposite of transclusion)