Wikipedia:Transclusion
From the Simple English Wikipedia, the free encyclopedia that anyone can change
Transclusion is generally 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.
Contents |
[change] 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.
This would be a pretty neat trick if it only meant that you didn't have to copy-and-paste from one page to another. For example, you might decide to copy a welcome message to every newcomer's Talk page; you could do this with transclusion (though it might not be the best thing to do!).
But transclusion creates a "live" link between the "template" page and the target page where it appears. When the template is edited, all the other pages change, 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.
[change] Examples
This very page uses template transclusion. The section above entitled "How transclusion works" is actually transcluded from the document Wikipedia:Transclusion/How_Transclusion_Works. That section is included by reference, by using the MediaWiki markup {{Wikipedia:Transclusion/How_Transclusion_Works}} to include it.
The template Flu at Template:Flu and text Spanish flu research at Spanish flu research are transcluded to Spanish flu using "{{Flu}}" and "{{:Spanish flu research}}" respectively.
Note that transcluding prose (not templates) in the main (article) namespace (such as the "{{:Spanish flu research}}" example) is currently a debated issue (see the links in the following sections). The alternative for substantial articles is to put a short introduction in the linking article and add a normal wikilink to the target, probably using the Template:Main or Template:Further templates.
[change] Pages related to MediaWiki transclusion
- Wikipedia:Transclusion costs and benefits
- Wikipedia:MediaWiki namespace
- m:Help:Variable
- Wikipedia talk:Template namespace#transcluding prose
[change] Templates
- m:Help:Template
- Wikipedia:Template namespace
- Wikipedia:Template limits
- Wikipedia:Avoid using meta-templates (rejected)
[change] See also
- Request for template transclusion from Commons (interwiki templates, etc.)
- Wikipedia:Template substitution (the opposite of transclusion)