→Subpages: added details and cleanup |
Fgnievinski (talk | contribs) m →Markup |
||
Line 110:
===Markup===
{{also|Help:Template#Noinclude, includeonly, and onlyinclude|Help:Category#
There are three pairs of [[html element|tags]] involved in cases where rendering should differ between the [[wikitext]] and 1) its preview rendering, and 2) its transclusion rendering. Tags are the invisible [[HTML#Elements|elements]] that affect how a page renders.
|
Revision as of 21:40, 3 November 2014
Transclusion means the inclusion of the content of one document in another document by reference. In Wikipedia transclusion, the MediaWiki software will refer to the content of one page, the template, for inclusion into the content of any other page, the target page. Similar to the way any 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, {{Namespace:Pagename}}. Changes made to the template are then automatically reflected on all pages into which that page has been transcluded (though a purge may sometimes be necessary).
If the template's 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:
- {{Like}} will transclude from the page Template:Like ( Like)
- {{Stochastic processes}} will transclude from the page Template:Stochastic processes
- {{:Stochastic processes}} will transclude from the page Stochastic processes (in the Main namespace)
- {{WP:Assume good faith}} will transclude from the page Wikipedia:Assume good faith
What will transclude from a page can be controlled with the tags <include>, <onlyinclude> and <includeonly> placed in the source page wikitext. (See 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 <includeonly> parts of the template are named (with the help of parser functions) and that template is then called with the parameter transcludesection=name.
Transclusion events occur every time the page is loaded, when the template is rendered. Another use of the same mechanism is a one-shot substitution of the template call itself with its transcluded source page. A template call {{fullpagename}} with the "subst:" prefix {{subst:fullpagename}} 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.
How transclusion works
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.
Basic syntax
The basic syntax for transclusion on Wikipedia is {{Namespace:Pagename}}
, where Namespace:Pagename
describes the title of a Wikipedia page.
On Wikipedia, non-article pages have titles with a visible Namespace and Pagename: for example, the page Wikipedia:Tips
has Wikipedia
as the Namespace, and Tips
as the Pagename. But encyclopedic articles only have a visible Pagename in their titles: for example, the article Potato
has Potato
as the Pagename; the Namespace, called Main Namespace, is not visible.
- Having the wikitext
{{Namespace:Pagename}}
in a page, will transclude the page titledNamespace:Pagename
into that page. For example, if a page has the wiki markup{{Wikipedia:Notability}}
in it, it will transclude the page Wikipedia:Notability into it. Please note:{{WP:Notability}}
would do the exactly the same thing, asWP:
is a namespace alias, which is automatically translated by the Wikipedia servers toWikipedia:
.
- If the namespace is omitted, but the colon is included, like
{{:Pagename}}
, the encyclopedic articlePagename
will be transcluded. For example,{{:Notability}}
will transclude the article Notability.
- If both namepace and colon are omitted, like
{{Pagename}}
, theTemplate:Pagename
will be transcluded. For example,{{Notability}}
, and also{{Template:Notability}}
, will both transclude the Template:Notability.
So, in summary, an example page having the wikitext {{Pagename}}
or {{Template:Pagename}}
included, will transclude the Template:Pagename
into that example page. But {{:Pagename}}
will have a different effect: it will transclude the Wikipedia encyclopedic article Pagename
. Also, {{Namespace:Pagename}}
will transclude the page Namespace:Pagename
, for pages with titles of that format.
Template transclusion
The most common application of transclusion is the transclusion of templates. Templates are pages that are written with the prime objective of being included in other pages, either through transclusion or substitution. As shown above, the usual syntax for transcluding a template titled Template:Pagename is {{Pagename}}
. However, some templates can also use parameters. Parameters are values (also termed arguments) that can be passed on to certain templates in order for them to work in different ways. Templates can either use no parameters, a fixed number of parameters, or a variable number of parameters. The number of parameters a template can use is from one upwards.
The exact syntax for using parameters with templates can vary greatly, depending on the actual template being used. But, for an example template titled Template:Pagename, which happened to use three parameters, the general form would be:
{{Pagename|parameter1|parameter2|parameter3}}
with each parameter being substituted with an actual value, or a parameter name=actual value, when used in practice. Notice that each parameter is separated with a vertical bar. Parameters that take the form value
are called unnamed or positional parameters. Parameters that take the form name=value
are called named parameters. With unnamed parameters, the first, second, third etc. parameters are equivalent to parameters '1', '2', '3' etc. in template documentation. Unnamed parameters must be in the correct order, and should come before any named parameters. An example of the syntax using the Template:Collapse top:
{{Collapse top|This is the title text|This is a custom warning line|left=true}}
In this particular example, three parameters are used, but it can actually use a variable number of parameters. This is the title text
and This is a custom warning line
are the values of unnamed parameters '1' and '2'; and true
is the value of the named parameter left
.
For more details, see Help:Template. Also, see Wikipedia:Template messages for a list of links to available Main Namespace related templates (usually for encyclopedic articles); and other Namespace related templates (usually for non-article pages); there is also a search function.
Subpages
To transclude a subpage, the general syntax is {{Namespace:Pagename/subpagename}}
. If it is a subpage of the page you are editing, then it is the general syntax, or {{/subpagename}}
. For an encyclopedic article it is {{:Pagename/subpagename}}
. For a template, it is the general syntax, or {{Pagename/subpagename}}
. For example, to transclude the Template:Like/doc, it would be either {{Template:Like/doc}}
or {{Like/doc}}
.
Substitution
Substitution has a similar double curly-bracket syntax, and its action is similar to transclusion. For example {{subst:Like}}
would substitute the Template:Like. But transclusion only occurs once, since when you save a page with that wikitext in it, it sustitutes the wikitext {{subst:Like}}
with the actual wikitext from the Template:Like. The main difference that this makes is that if an update happened to the wikitext of the Template:Like, it would not update any pages where {{subst:Like}}
had already been saved.
Magic words
Some magic words have a similar double curly-bracket syntax, and have a similar action to transclusion. For example, {{FULLPAGENAME}}
renders the Fullpagename of any Wikipedia page. Some magic words can also take parameters, which are seperated using a colon (:); for example {{FULLPAGENAME:value}}
. But they are not examples of transclusion.
Templates do exist for some magic words, for example Template:FULLPAGENAME; but these just invoke the related magic word if passing parameters using a vertical bar (|); for example like {{FULLPAGENAME|value}}
. But magic words parameters are best passed directly by using a colon, for example like {{FULLPAGENAME:value}}
, which bypasses any templates.
Applications of transclusion
The most common application of transclusion is in the use of templates. However, other pages are also sometimes transcluded, mainly within project space.
Composite pages
The wikitext of a page may (partly or fully) consist of tags for the inclusion of component pages. The component pages are usually not in the template namespace, and are often full pages in their own right. Composite pages are intended to gather the material on them into a central location.
Examples are:
- m:Help:A simple composite example
- Wikipedia:Village pump with six component pages, e.g. Wikipedia:Village pump (technical)
- A daily page like Wikipedia:Votes for deletion/Log/2005 May 31 where each component page consists of the discussion on the deletion of one Wikipedia page, e.g. Wikipedia:Votes for deletion/Sp3tt (for this day there are 75 such component pages)
- m:Meta:Translation/Coordination, mainly containing
This allows the choice between viewing the component pages separately or together. Viewing a composite page is convenient when there are many small, related component pages, in that it allows an overview of all the components without the effort of following numerous links.
In general, each component page and the composite page are treated separately. While the actual changes on the component pages will be transcluded onto the composite page, the edit history, recent changes, page-watch settings, page protection, TOC, "what links here" link, and other features of the composite page do not reflect or affect the histories, watch settings, protection levels, what links here lists of the component pages. The composite page is a page in its own right. The talk page of a composite page is used to talk about the composition and the page in general, not the component pages, though it in turn could be a composite of the talk pages of the component pages.
Editing a section of a component page can be done directly from the composite page, see editing sections of included templates. After saving, one ends up at the page for the component page to which the section belongs.
On projects with the interlanguage link feature the composite page shows the combined interlanguage links of all component pages, hence possibly multiple links for one language or even for one page.
See also Wikipedia talk:Template namespace/Archive 1#transcluding prose.
Pages with a common section
When two pages need to discuss the same material in the same way, they can share a section. This involves 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, and if the first it may be placed in the same namespace as the other pages or in template namespace. 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 disambiguation pages share content, or a list page and a disambiguation page share content (see third example below).
Examples:
- m:Help:Editing sections of included templates (talk, backlinks, )
- m:Help:Alphabetic order (talk, backlinks, )
- Slough (disambiguation) transcludes Slough (hydrology), since the content of the former is nearly identical to one section of the latter.
Repetition within a page
On pages where there is a lot of repetitive information — various kinds of lists, usually — it is sometimes useful to make a template that contains the repeating text, and then call that template multiple times. For example, Template:EH listed building row is used repeatedly to construct tables in many articles.
Simple repetition of the same text can be handled with repetition of a parameter in a single template: e.g., {{3x}}, where {{3x| howdy!}} produces howdy! howdy! howdy!.
For more information on repetition see also m:Help:Recursive conversion of wikitext.
For more information on the current template system, see Wikipedia:Template namespace.
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 how History of pathology [1] was transcluded into Pathology,[2] which consisted of a collection of transcluded lead paragraphs from several main articles.
Markup
There are three pairs of tags involved in cases where rendering should differ between the wikitext and 1) its preview rendering, and 2) its transclusion rendering. Tags are the invisible elements that affect how a page renders. Let's call a preview "rendered here", and a transclusion "rendered there".
A transcluded page name is no different than its preview. But the tags pair-off to demarcate sections that will affect differences. Each tag name will describe its invisibility exception to transcluding the whole page named.
- <noinclude>material invisible there </noinclude>
- <includeonly>material invisible here </includeonly>
- <onlyinclude>material outside this section invisible there </onlyinclude>
"Only" is not a term to reckon with because it means "only there" in the one, but "only this" in the other.
There can be several such sections. Also, they can be nested. All possible differences between here and there are achievable. The one example is a content editor who picks an onlyInclude section and takes a noInclude section out of that, picks out yet another onlyInclude section to append to there, while none of this effects their article in any way. The other example is the template programmer who will includeOnly the code section and noInclude the documentation section of a page. A mis-example is the user page includeOnly section: it might "comment out" sections here, but such invisible ink may prove to be troublesome, and transcluded the comments would be revealed commenting on nothing.
NoInclude as a name about transcluding is pretty straightforward. A mnemonic for the other two transclusions there is: InclusionONLY; and Yet Another ONLYInclusion.
Selective transclusion
Selective transclusion is the process of partially transcluding one selected section of a document that has more than one transcludable section. As noted above, if only one section of a document is to be transcluded, this can be done by simply surrounding the section of interest with <onlyinclude> … </onlyinclude> tags, and transcluding the whole page. However, to selectively transclude one section from a template or document into one page, and another section from the same template or document into another page, requires a way to:
- a) uniquely mark each transcludable section in the source document; and
- b) in the target document(s) (those to show the transcluded sections), a way to specify which section is to be transcluded.
This section describes how to accomplish this.
Labeled section transclusion
Labeled section transclusion uses mw:Extension:Labeled Section Transclusion which is enabled on all Wikimedia wikis. See Help:Labeled section transclusion for how it works. The following subsections are about a more complicated way to make selective transclusion without using the extension.
Source document markup
Insert the following line into the "source" document (the one from which text is to be transcluded), immediately preceding the first line of each section to be transcluded, substituting SECTIONNAME (twice) with the unique name of the respective section. The section name can be any identifier and must be unique within that document:
- <onlyinclude>{{#ifeq:{{{transcludesection|SECTIONNAME}}}|SECTIONNAME|
End each such transcludable section with:
- }}</onlyinclude>
Target document markup
To transclude a section marked as above into another page (the "target page"), use the following line on that page, substituting PAGENAME for the "source" document from which text to be transcluded, and SECTIONNAME with the name of the section you want to transclude:
- {{PAGENAME|transcludesection=SECTIONNAME}}
Thus each section enclosed within <onlyinclude> … </onlyinclude> tags will always be rendered when the transcludesection parameter is not set (when the document is viewed ordinarily, or when the document is transcluded without setting the transcludesection parameter as shown below), and will be rendered by transclusion on any page that does set transcludesection to the section's name. It will not be rendered by transclusion that uses the transcludesection parameter but sets it to anything other than the name of the section.
Also, when providing PAGENAME, without providing a Namespace, the wiki will assume that the PAGENAME belongs in the Template Namespace. To transclude from a Mainspace article, use :PAGENAME.
- {{:PAGENAME|transcludesection=SECTIONNAME}}
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:
- <onlyinclude>{{#ifeq:{{{transcludesection|principalcriteria}}}|principalcriteria|
- ...
- (text of "Principal Criteria" section)
- ...
- }}</onlyinclude>
Similarly, we enclose the "Common Name" section with:
- <onlyinclude>{{#ifeq:{{{transcludesection|commonname}}}|commonname|
- ...
- (text of "Common Name" section)
- ...
- }}</onlyinclude>
Then, to transclude the "Principal Criteria" section into another page, we insert into that page:
- {{WP:TITLE|transcludesection=principalcriteria}}
To transclude the "Common Name" section into another page, we insert into that page:
- {{WP:TITLE|transcludesection=commonname}}
Of course, the same page can transclude two or more sections this way by including multiple such lines.
There is no limit to how many selectable sections for transclusion a document can have. The only requirement is that each transcludesection be given a value that is unique within that page.
Subpages
You can also transclude from a subpage. For example, you could place some text in a subpage, and then use the name of the subpage in the transclusion template, like {{Namespace:Pagename/subpagename}}
. Subpages can only allowed in certain namespaces, such as User, Talk or Wikipedia pages; currently, subpages of main article pages cannot be created.
For example: you want to discuss the deletion and redirecting of the article Pussycat to the article Cat in both talk pages. 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 this subpage will be shown in both talk pages. To ease the editing of the subpage, it may be helpful to precede the transcluded talk with {{lat}}; for example the wikitext {{lat|Pussycat/Let's delete Pussycat!}}
would produce Talk:Pussycat/Let's delete Pussycat! ( | article | history | links | watch | logs). Transcluding in this way will not preserve a fixed record of the discussion at the time of any archiving, so discussions should be closed in conjunction with archiving.
An alternative is not to use subpages at all. You could centralise the discussion, in the normal manner, on a single talk page, and point to it on the other talk page by substituting the {{Please see}} template, as per WP:MULTI. As an example, a discussion could take place at Talk:Pussycat#Let's delete Pussycat!; you could then place the wikitext {{subst:Please see|Talk:Pussycat#Let's delete Pussycat!}}
in the Talk:Cat page. When the edit was saved, it would substitute it with the text:
==Discussion at Talk:Pussycat#Let's delete Pussycat!==
[[File:Farm-Fresh eye.png|15px|link=|alt=]] You are invited to join the discussion at [[Talk:Pussycat#Let's delete Pussycat!]]. Thanks. [[User:Example|Example]] ([[User talk:Example|talk]]) 19:03, 20 October 2014 (UTC){{z48}}<!--Template:Please see-->
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.
URL parameters can be given like template parameters:
- {{Special:Recentchanges|namespace=10|limit=5}} – the five most recent changes in the "Template" namespace
Note: Transcluding certain special pages (such as Special:Newpages) can change the displayed title of the page.
Pages related to MediaWiki transclusion
- m:Help:A simple composite example
- Wikipedia:MediaWiki namespace
- m:Help:Variable
- Wikipedia talk:Template namespace#transcluding prose
- mw:Extension:Labeled Section Transclusion
- Mediawiki help -- Labeled Section Transclusion
- Help:Labeled section transclusion
Templates
See also
- Wikipedia:Transclusion costs and benefits
- Wikipedia:Purge (to force transclusion of newly updated templates)
- Wikipedia:Substitution (the opposite of transclusion)
- Wikipedia:WikiProject Modular Articles
- Bugzilla:Request for template transclusion from Commons (interwiki templates, etc.)