Help:Transclusion

From K6ka's Wiki
Jump to navigation Jump to search
This page is a help page
It is meant to detail processes or procedures of some aspect or aspects of K6ka's Wiki's norms and practices. It is not a policy page.
An example of how transclusion works. Here, the page "B" is being transcluded onto pages "A", "P", and "Q". The contents of "B" will appear in the spot where {{B}} is used on the page. The top row shows what the target page will render as, while the bottom row shows the wikitext code of the page.

Transclusion refers to the act of displaying the contents of one page onto another. This is done in a similar way to creating page links, except that curly braces are used instead of square brackets. For example, to link to the "Help:Editing" page, type [[Help:Editing]]. To transclude the contents of "Help:Editing", type {{Help:Editing}}. This will then cause the contents of "Help:Editing" to appear on the current page. When "Help:Editing" is later edited, the changes made will automatically be propagated to the pages that transclude "Help:Editing" (though a purge may be necessary).

Transclusion is usually used for templates, where the contents of one page are designed to be inserted into multiple pages, although transclusion can be used for other contexts as well.

Syntax[edit source]

The basic syntax for transclusion is providing the full name of the page surrounded in curly brackets. Because transclusion is primarily intended for templates, if the namespace prefix is excluded, the target will default to the template namespace. This means that typing {{Foo}} has the same effect as typing {{Template:Foo}}; both will transclude the page "Template:Foo".

If a valid namespace prefix is provided, the corresponding page in that namespace will be transcluded. For example, to transclude the page "Help:Editing", type {{Help:Editing}}. If the namespace prefix provided is not valid (i.e. the namespace does not exist), it will default back to the template namespace.

To transclude pages from the main namespace (which do not have a namespace prefix in the title), a colon must be added immediately after the first set of curly brackets. For example, to transclude the page "Apple", type {{:Apple}}.

More advanced usage of transclusion syntax can be found on Help:Template. Although the page primarily covers templates created in the template namespace, it is possible for such code to be included in any namespace.

Applications[edit source]

Transclusion has a wide variety of different uses, and are not solely limited to templates. Transclusion is very commonly used in the project namespace. For example, it may be useful to create a "composite page" that contains multiple different pages transcluded onto it in order to form a centralized hub where everything can be seen on the same page.

Articles can make use of transclusions as well. It may sometimes be useful to create lists and tables on a separate page and then transclude it into a more-commonly accessed page. This can be used if the list or table needs to be shown in multiple locations. If transclusion is used, the list or table will only need to be edited once for all changes to be propagated to other pages.

Partial transclusion[edit source]

See also: Help:Template § Noinclude, includeonly, and onlyinclude

It is possible to specify only specific parts of a page to be transcluded. The <noinclude>, <includeonly>, and <onlyinclude> tags can be used to this effect. When these tags are used, only parts of a page will appear when it is transcluded into another.

  • <noinclude> . . . </noinclude> will not include any of the contents placed inside of them onto target pages when the page is transcluded.
  • <includeonly> . . . </includeonly> will include any of the contents placed inside of them onto target pages when the page is transcluded, but said content will not appear when the page is viewed directly.
  • <onlyinclude> . . . </onlyinclude> will include any of the contents placed inside of them onto target pages and when the page is viewed directly, but anything not placed between these tags will not be transcluded.
Wikitext What is rendered here (source page) What is transcluded there (destination page)
<noinclude> text1 </noinclude> text2 text1 text2 text2
<onlyinclude> text1 </onlyinclude> text2 text1 text2 text1
<includeonly> text1 </includeonly> text2 text2 text1 text2

Subpages[edit source]

Subpages are transcluded like any other page (e.g. {{Namespace:Pagename/Subpagename}}. However, if the page being transcluded is a subpage of the current page, it is possible to omit the first part of the name and only include {{/Subpagename}}. For example, if you were editing the page "Foo", and you wanted to transclude the page "Foo/Bar" onto it, you can simply write {{/Bar}}.

Special pages[edit source]

Some special pages allow themselves to be transcluded. Examples include Special:Allpages, Special:Prefixindex, Special:Newfiles, Special:Newpages, Special:Recentchanges and Special:Recentchangeslinked.

  • {{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".

URL parameters can be given like template parameters. For example, {{Special:Recentchanges|namespace=10|limit=5}} will give the five most recent changes in the template namespace.

See also[edit source]