Help:Transclusion: Difference between revisions
Orangestar (talk | contribs) m 1 revision imported |
Orangestar (talk | contribs) m Text replacement - "[[WP:" to "[[wikipedia:WP:" |
||
Line 6: | Line 6: | ||
{{Broader|Transclusion}} | {{Broader|Transclusion}} | ||
{{Information page|H:TRANS|H:TRANSCL|WP:TRANS|WP:TRANSCL}} | {{Information page|H:TRANS|H:TRANSCL|WP:TRANS|WP:TRANSCL}} | ||
'''Transclusion''' means the inclusion of the content of one document within another document by [[Reference (computer science)|reference]]. In Wikipedia transclusion, the [[MediaWiki]] software will refer to the content of one page, the [[WP:template|template]], for inclusion into the content of any other page, the target page. Similar to the way any [[wp:page name|page name]] can become a link by placing its name in double square brackets, any page name can become a template by placing it in double curly braces, '''<syntaxhighlight lang="wikitext" inline>{{Namespace:Pagename}}</syntaxhighlight>'''. Changes made to the template are then automatically reflected on all pages into which that page has been transcluded (though a [[Wikipedia:Purge|purge]] may sometimes be necessary). | '''Transclusion''' means the inclusion of the content of one document within another document by [[Reference (computer science)|reference]]. In Wikipedia transclusion, the [[MediaWiki]] software will refer to the content of one page, the [[wikipedia:WP:template|template]], for inclusion into the content of any other page, the target page. Similar to the way any [[wp:page name|page name]] can become a link by placing its name in double square brackets, any page name can become a template by placing it in double curly braces, '''<syntaxhighlight lang="wikitext" inline>{{Namespace:Pagename}}</syntaxhighlight>'''. Changes made to the template are then automatically reflected on all pages into which that page has been transcluded (though a [[Wikipedia:Purge|purge]] may sometimes be necessary). | ||
If the template's [[WP:page name|page name]] does not begin with a namespace, it is assumed to be in the Template namespace. To refer to a page in the "Main" (article) namespace, it is necessary to prefix it with a colon (''':'''). Examples: | If the template's [[wikipedia:WP:page name|page name]] does not begin with a namespace, it is assumed to be in the Template namespace. To refer to a page in the "Main" (article) namespace, it is necessary to prefix it with a colon (''':'''). Examples: | ||
* '''<syntaxhighlight lang="wikitext" inline>{{Stochastic processes}}</syntaxhighlight>''' will transclude from the page [[:Template:Stochastic processes]] | * '''<syntaxhighlight lang="wikitext" inline>{{Stochastic processes}}</syntaxhighlight>''' will transclude from the page [[:Template:Stochastic processes]] | ||
Line 16: | Line 16: | ||
What will transclude from a page can be controlled with the tags <<nowiki/>noinclude>, <<nowiki/>onlyinclude> and <<nowiki/>includeonly> placed in the source page wikitext. (See [[#Markup|markup]], below.) The use of tags enables the template to transclude partially, otherwise the double curly braces will always transclude all content. For ''selective'' transclusion the <<nowiki/>includeonly> parts of the template are named (with the help of [[wp:parser functions|parser functions]]) and that template is then called with the [[Help:Template#Parameters|parameter]] <code>transcludesection=''name''</code>. | What will transclude from a page can be controlled with the tags <<nowiki/>noinclude>, <<nowiki/>onlyinclude> and <<nowiki/>includeonly> placed in the source page wikitext. (See [[#Markup|markup]], below.) The use of tags enables the template to transclude partially, otherwise the double curly braces will always transclude all content. For ''selective'' transclusion the <<nowiki/>includeonly> parts of the template are named (with the help of [[wp:parser functions|parser functions]]) and that template is then called with the [[Help:Template#Parameters|parameter]] <code>transcludesection=''name''</code>. | ||
Transclusion events occur every time the page is ''loaded'', when the template is rendered. Another use of the same mechanism is a one-shot ''[[Help:substitution|substitution]]'' of the template call itself by its transcluded source page. A template call <code>{<nowiki/>{''[[WP:page name#Namespace, pagename, and fullpagename|fullpagename]]''}}</code> with the "subst:" prefix <syntaxhighlight lang="wikitext" inline>{{subst:fullpagename}}</syntaxhighlight> is transcluded once but never again, because the wikitext of that call is replaced (substituted) when its page is ''saved''. What was a one-time template call becomes the actual wikitext of the template at the time of its call. | Transclusion events occur every time the page is ''loaded'', when the template is rendered. Another use of the same mechanism is a one-shot ''[[Help:substitution|substitution]]'' of the template call itself by its transcluded source page. A template call <code>{<nowiki/>{''[[wikipedia:WP:page name#Namespace, pagename, and fullpagename|fullpagename]]''}}</code> with the "subst:" prefix <syntaxhighlight lang="wikitext" inline>{{subst:fullpagename}}</syntaxhighlight> is transcluded once but never again, because the wikitext of that call is replaced (substituted) when its page is ''saved''. What was a one-time template call becomes the actual wikitext of the template at the time of its call. | ||
Transclusion runs in advance of parsing the target page at the HTML layer, so it is possible to emit syntax fragments—even fragments of entity references, such as "&a" and "mp;"—that will parse successfully as combined text in the target page.<!-- tested on an older MediaWiki --> As a design idiom, this tends to violate the principle of least surprise, so it should be used sparingly, when cleaner solution paths do not present themselves. Emitting fragments of template syntax, such as a pair of opening braces, is unlikely to successfully re-parse as template syntax in the target page.<!-- tested on an older MediaWiki --> Even if this worked, it would be unwise to depend upon this as supported behaviour, unless formally documented. | Transclusion runs in advance of parsing the target page at the HTML layer, so it is possible to emit syntax fragments—even fragments of entity references, such as "&a" and "mp;"—that will parse successfully as combined text in the target page.<!-- tested on an older MediaWiki --> As a design idiom, this tends to violate the principle of least surprise, so it should be used sparingly, when cleaner solution paths do not present themselves. Emitting fragments of template syntax, such as a pair of opening braces, is unlikely to successfully re-parse as template syntax in the target page.<!-- tested on an older MediaWiki --> Even if this worked, it would be unwise to depend upon this as supported behaviour, unless formally documented. | ||
Line 27: | Line 27: | ||
==Transclusion syntax== | ==Transclusion syntax== | ||
The general [[Syntax (programming languages)|syntax]] for [[Transclusion|transclusion]] on Wikipedia is <syntaxhighlight lang="wikitext" inline>{{Namespace:Pagename}}</syntaxhighlight>, where <code>[[WP:Namespace|Namespace]]:[[WP:Page name|Pagename]]</code> describes the title of a Wikipedia page. | The general [[Syntax (programming languages)|syntax]] for [[Transclusion|transclusion]] on Wikipedia is <syntaxhighlight lang="wikitext" inline>{{Namespace:Pagename}}</syntaxhighlight>, where <code>[[wikipedia:WP:Namespace|Namespace]]:[[wikipedia:WP:Page name|Pagename]]</code> describes the title of a Wikipedia page. | ||
Using transclusion syntax requires some knowledge of page titles. On Wikipedia, non-article pages have titles with a visible namespace and pagename separated by a colon; for example, the page [[Wikipedia:Tips]] has <code>Wikipedia</code> as the namespace, and <code>Tips</code> as the pagename. But encyclopedic articles only have a visible pagename in their titles: for example the article [[Potato]] has <code>Potato</code> as the pagename, and the namespace, called [[Wikipedia:What is an article?#Namespace|main namespace]], is not visible. | Using transclusion syntax requires some knowledge of page titles. On Wikipedia, non-article pages have titles with a visible namespace and pagename separated by a colon; for example, the page [[Wikipedia:Tips]] has <code>Wikipedia</code> as the namespace, and <code>Tips</code> as the pagename. But encyclopedic articles only have a visible pagename in their titles: for example the article [[Potato]] has <code>Potato</code> as the pagename, and the namespace, called [[Wikipedia:What is an article?#Namespace|main namespace]], is not visible. | ||
Line 109: | Line 109: | ||
===Pages with a common section=== | ===Pages with a common section=== | ||
{{shortcut|WP:COMMONSECTION}} | {{shortcut|WP:COMMONSECTION}} | ||
When two pages need to discuss the same material in the same way, they can share a section. For example, a section of an existing page may be transcluded on other pages. This may also involve creating a third page and transcluding that page onto both pages. This third page may be a page in its own right or a subpage of either of the other two – except in article space, where subpages are not allowed (see [[WP:SUB]]). The third page may be placed in the same namespace as the other pages or in template namespace – again, except for use in article space, where templates should not store article text (see [[WP:TG]]). Common sections like this should be marked with an explanatory header, and/or given a special layout, to inform the reader that this section of the page is in a different location, since transcluding shared article sections can easily confuse novice editors and readers alike if left unmarked. | When two pages need to discuss the same material in the same way, they can share a section. For example, a section of an existing page may be transcluded on other pages. This may also involve creating a third page and transcluding that page onto both pages. This third page may be a page in its own right or a subpage of either of the other two – except in article space, where subpages are not allowed (see [[wikipedia:WP:SUB]]). The third page may be placed in the same namespace as the other pages or in template namespace – again, except for use in article space, where templates should not store article text (see [[wikipedia:WP:TG]]). Common sections like this should be marked with an explanatory header, and/or given a special layout, to inform the reader that this section of the page is in a different location, since transcluding shared article sections can easily confuse novice editors and readers alike if left unmarked. | ||
This can be very useful when two [[WP:DAB|disambiguation]] pages share content,{{Disputed inline|talk=Wikipedia talk:Manual of Style/Disambiguation pages#Transclusion|date=September 2017}} or a list page and a disambiguation page share content (see third example below). | This can be very useful when two [[wikipedia:WP:DAB|disambiguation]] pages share content,{{Disputed inline|talk=Wikipedia talk:Manual of Style/Disambiguation pages#Transclusion|date=September 2017}} or a list page and a disambiguation page share content (see third example below). | ||
Examples: | Examples: | ||
Line 143: | Line 143: | ||
In transclusion, a source page is transcluded into a destination page. But with partial transclusion, only part of that source page will be transcluded into a destination page. But in addition, what is transcluded to a destination page does not have to be visible on the source page. | In transclusion, a source page is transcluded into a destination page. But with partial transclusion, only part of that source page will be transcluded into a destination page. But in addition, what is transcluded to a destination page does not have to be visible on the source page. | ||
''Page rendering'' of a source page can be defined as the rendering of that source page when it is saved, which will be the same as the [[WP:preview|preview]]. We can call this rendering '''''here'''''. | ''Page rendering'' of a source page can be defined as the rendering of that source page when it is saved, which will be the same as the [[wikipedia:WP:preview|preview]]. We can call this rendering '''''here'''''. | ||
''Transclusion rendering'' of a source page can be defined as the rendering of a destination page that has a source page transcluded into it; but only that part of the destination page that was transcluded from the source page. The preview of the transclusion rendering will again be identical. We can call this rendering '''''there'''''. | ''Transclusion rendering'' of a source page can be defined as the rendering of a destination page that has a source page transcluded into it; but only that part of the destination page that was transcluded from the source page. The preview of the transclusion rendering will again be identical. We can call this rendering '''''there'''''. | ||
Line 211: | Line 211: | ||
===Using the labeled section method=== | ===Using the labeled section method=== | ||
{{main|Help:Labeled section transclusion}} | {{main|Help:Labeled section transclusion}} | ||
Labeled-section selective transclusion uses the [[WP:PF|parser function]]s listed in [[mw:Extension:Labeled Section Transclusion]], which are enabled on all Wikimedia wikis, to selectively transclude content. See [[Help:Labeled section transclusion]] for how labeled section transclusion works. | Labeled-section selective transclusion uses the [[wikipedia:WP:PF|parser function]]s listed in [[mw:Extension:Labeled Section Transclusion]], which are enabled on all Wikimedia wikis, to selectively transclude content. See [[Help:Labeled section transclusion]] for how labeled section transclusion works. | ||
===Parametrization method=== | ===Parametrization method=== | ||
Line 232: | Line 232: | ||
=====Example===== | =====Example===== | ||
If we want to make the "Principal Criteria" and "Common Name" sections of [[WP:TITLE]] be independently transcludable, we edit the WP:TITLE page and enclose the "Principal Criteria" section as follows: | If we want to make the "Principal Criteria" and "Common Name" sections of [[wikipedia:WP:TITLE]] be independently transcludable, we edit the WP:TITLE page and enclose the "Principal Criteria" section as follows: | ||
<syntaxhighlight lang="xml+smarty"> | <syntaxhighlight lang="xml+smarty"> | ||
<onlyinclude>{{#ifeq:{{{transcludesection|principalcriteria}}}|principalcriteria| | <onlyinclude>{{#ifeq:{{{transcludesection|principalcriteria}}}|principalcriteria| | ||
Line 269: | Line 269: | ||
If there is a wikilink to the parent article in the lead section of the sub-article, replacing the wikilink to the parent article with a {{tlx|no selflink}} template will ensure that it is wikilinked in the sub-article's lead but not in the transclusion to the parent article. In other words: | If there is a wikilink to the parent article in the lead section of the sub-article, replacing the wikilink to the parent article with a {{tlx|no selflink}} template will ensure that it is wikilinked in the sub-article's lead but not in the transclusion to the parent article. In other words: | ||
# If the wikilink to the parent article is not a [[WP:Piped link]], replace <code>[[{{var|PARENT_ARTICLE}}]]</code> with {{tnull|no selflink|{{var|PARENT_ARTICLE}}}} in the sub-article's lead | # If the wikilink to the parent article is not a [[wikipedia:WP:Piped link]], replace <code>[[{{var|PARENT_ARTICLE}}]]</code> with {{tnull|no selflink|{{var|PARENT_ARTICLE}}}} in the sub-article's lead | ||
# If the [[Wikipedia:Piped link|wikilink to the parent article includes a pipe (e.g., this link)]], replace <code>[[{{var|PARENT_ARTICLE}}|{{var|Piped link wikitext}}]]</code> with {{tnull|No selflink|{{var|PARENT_ARTICLE}}|{{var|Piped link wikitext}}}} in the sub-article's lead | # If the [[Wikipedia:Piped link|wikilink to the parent article includes a pipe (e.g., this link)]], replace <code>[[{{var|PARENT_ARTICLE}}|{{var|Piped link wikitext}}]]</code> with {{tnull|No selflink|{{var|PARENT_ARTICLE}}|{{var|Piped link wikitext}}}} in the sub-article's lead | ||
Line 278: | Line 278: | ||
Like many software technologies, transclusion comes with a number of drawbacks. The most obvious one being the cost in terms of increased machine resources needed; to mitigate this to some extent, [[Wikipedia:Template limits|template limits]] are imposed by the software to reduce the complexity of pages. Some further drawbacks are listed below. | Like many software technologies, transclusion comes with a number of drawbacks. The most obvious one being the cost in terms of increased machine resources needed; to mitigate this to some extent, [[Wikipedia:Template limits|template limits]] are imposed by the software to reduce the complexity of pages. Some further drawbacks are listed below. | ||
*Transcluded text may have [[Wikipedia:Verifiability|no sources]] for statements that should be [[WP:BURDEN|sourced where they appear]], have different [[WP:CITEVAR|established reference styles]], contain [[Help:Cite errors/Cite error references no text|no-text cite errors]], or [[Help:Cite errors/Cite error references duplicate key|duplicate key errors]]. (To help mitigate these, see [[Help:Cite errors]]) | *Transcluded text may have [[Wikipedia:Verifiability|no sources]] for statements that should be [[wikipedia:WP:BURDEN|sourced where they appear]], have different [[wikipedia:WP:CITEVAR|established reference styles]], contain [[Help:Cite errors/Cite error references no text|no-text cite errors]], or [[Help:Cite errors/Cite error references duplicate key|duplicate key errors]]. (To help mitigate these, see [[Help:Cite errors]]) | ||
*Excerpts break the link between article code and article output. | *Excerpts break the link between article code and article output. | ||
*Changes made to transcluded content often do not appear in watchlists, resulting in unseen changes on the target page. | *Changes made to transcluded content often do not appear in watchlists, resulting in unseen changes on the target page. | ||
*Transcluded text may cause [[MOS:REFLINK|repeated links]] or have different [[MOS:ENGVAR|varieties of English]] and [[WP:DATERET|date formats]] than the target page. | *Transcluded text may cause [[MOS:REFLINK|repeated links]] or have different [[MOS:ENGVAR|varieties of English]] and [[wikipedia:WP:DATERET|date formats]] than the target page. | ||
*Transclusions may not reflect [[Wikipedia:Protection policy|protection levels]], resulting in transcluded text perhaps having a different [[WP:PPLIST|level of protection]] than the target page. See [[WP:CASCADE|Cascading protection]] | *Transclusions may not reflect [[Wikipedia:Protection policy|protection levels]], resulting in transcluded text perhaps having a different [[wikipedia:WP:PPLIST|level of protection]] than the target page. See [[wikipedia:WP:CASCADE|Cascading protection]] | ||
*{{tl|excerpt}} and related templates may require using {{tag|noinclude|o}}, {{tag|includeonly|o}} and {{tag|onlyinclude|o}} markup at the transcluded page to have [[WP:SELECTIVETRANSCLUSION|selective content]]; that would require monitoring that the markup is sustained. | *{{tl|excerpt}} and related templates may require using {{tag|noinclude|o}}, {{tag|includeonly|o}} and {{tag|onlyinclude|o}} markup at the transcluded page to have [[wikipedia:WP:SELECTIVETRANSCLUSION|selective content]]; that would require monitoring that the markup is sustained. | ||
*Excerpts cause editors to monitor transcluded pages for "section heading" changes to ensure transclusion continues to work. (To help mitigate this, see [[MOS:BROKENSECTIONLINKS]]) | *Excerpts cause editors to monitor transcluded pages for "section heading" changes to ensure transclusion continues to work. (To help mitigate this, see [[MOS:BROKENSECTIONLINKS]]) | ||
*Excerpts can result in content discussions [[WP:CROSS-POST|over multiple talk pages]] that may have different considerations or objectives for readers. | *Excerpts can result in content discussions [[wikipedia:WP:CROSS-POST|over multiple talk pages]] that may have different considerations or objectives for readers. | ||
==Special pages== | ==Special pages== | ||
Line 328: | Line 328: | ||
** [[mw:Help:Template]]: a simple introduction at MediaWiki. | ** [[mw:Help:Template]]: a simple introduction at MediaWiki. | ||
* [[Wikipedia:Template index]]: a directory of available templates. | * [[Wikipedia:Template index]]: a directory of available templates. | ||
* [[Wikipedia:Template namespace]]: about the template [[WP:Namespace|namespace]]. | * [[Wikipedia:Template namespace]]: about the template [[wikipedia:WP:Namespace|namespace]]. | ||
* [[Wikipedia:Template limits]]: limitations to complexity of pages. | * [[Wikipedia:Template limits]]: limitations to complexity of pages. | ||