Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Help:Transclusion
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
==Transclusion syntax== The general [[Syntax (programming languages)|syntax]] for transclusion on Wikipedia follows the format <syntaxhighlight lang="wikitext" inline="">{{Namespace:Pagename}}</syntaxhighlight>, where <code>[[Wikipedia:Namespace|Namespace]]:[[Wikipedia:Page name|Pagename]]</code> specifies the [[Wikipedia:Title|title]] of a Wikipedia page. Similar to creating a [[Wikipedia:Link|wikilink]] using double square brackets (<code><syntaxhighlight lang="wikitext" inline="">[[Pagename]]</syntaxhighlight></code>), a page can be transcluded as a template by enclosing its title in double curly braces: <syntaxhighlight lang="wikitext" inline="">{{Namespace:Pagename}}</syntaxhighlight>. Any changes made to the source page, or template, are automatically reflected on all pages that include the transcluded content.{{refn|group=lower-alpha|A [[Wikipedia:Purge|purge]] may occasionally be necessary to refresh target pages, ensuring they retrieve and display the latest content from the template or source page. This forces the MediaWiki software to clear the cached version of the page and reload it with the most up-to-date transcluded content.}} Wikipedia is structured using [[Wikipedia:Namespace|namespaces]], which organize pages based on their function. For example, a page titled {{Xtn|[[Wikipedia:Tips]]}} belongs to the Wikipedia namespace, with <code>Wikipedia:</code> as its namespace and <code>Tips</code> as its pagename. However, articles in the [[Wikipedia:Mainspace|Main namespace]], such as {{Xtn|[[Potato]]}}, do not require a namespace prefix when linked using <code><syntaxhighlight lang="wikitext" inline="">[[Potato]]</syntaxhighlight></code>, as Wikipedia assumes any wikilink without a specified namespace belongs to the Article namespace. When transcluding pages, if no namespace is specified, Wikipedia defaults to the [[Wikipedia:Template namespace|Template namespace]]. To reference a page in the Article namespace within transclusion syntax, it ''must'' be explicitly prefixed with a colon {{Char|:}} (e.g., <syntaxhighlight lang="wikitext" inline="">{{:Potato}}</syntaxhighlight>). === Examples === {| class="table" style="padding:0.25em; margin-bottom:0.5em; border: 1px #dadde3 solid; background-color: #F5FAFF;" | style="vertical-align:top;" | {{nowrap|[[File:Dialog-information.svg|20px|alt=blue lightbulb]] '''Outline''':}} || using <syntaxhighlight lang="wikitext" inline>{{Pagename}}</syntaxhighlight> or <syntaxhighlight lang="wikitext" inline>{{Template:Pagename}}</syntaxhighlight> will transclude the content of {{Xtn|{{fake link|Template:Pagename}}}}. Using <syntaxhighlight lang="wikitext" inline>{{:Pagename}}</syntaxhighlight> instead will transclude the mainspace article titled {{Xtn|{{fake link|Pagename}}}}. Including <syntaxhighlight lang="wikitext" inline>{{Namespace:Pagename}}</syntaxhighlight> transcludes a page in the defined namespace, such as {{Xtn|{{fake link|Help:Pagename}}}}. |} * '''Specifying namespace''': <syntaxhighlight lang="wikitext" inline>{{Namespace:Pagename}}</syntaxhighlight> will transclude the page titled <syntaxhighlight lang="wikitext" inline>Namespace:Pagename</syntaxhighlight>. For example, if a page has the wikitext <syntaxhighlight lang="wikitext" inline>{{Wikipedia:Notability}}</syntaxhighlight> in it, it will transclude the page {{Xtn|[[Wikipedia:Notability]]}} into it. Please note that <syntaxhighlight lang="wikitext" inline>{{WP:Notability}}</syntaxhighlight> would do exactly the same thing, as <code>WP:</code> is a [[Wikipedia:Namespace#Aliases|namespace alias]], which is [[Wikipedia:Shortcut#Namespace_aliases|automatically translated]] by the Wikipedia servers to <code>Wikipedia:</code>. * '''Calling from the Article namespace''': If the namespace is omitted, but the colon is included, like <syntaxhighlight lang="wikitext" inline>{{:Pagename}}</syntaxhighlight>, the mainspace article <code>Pagename</code> will be transcluded. For example, <syntaxhighlight lang="wikitext" inline>{{:Notability}}</syntaxhighlight> will transclude the article [[Notability|{{Xtn|[[Notability]]}}]]. * '''Template namespace''': If both namespace and colon are omitted, like <syntaxhighlight lang="wikitext" inline>{{Pagename}}</syntaxhighlight>, the <code>Template:Pagename</code> will be transcluded. For example <syntaxhighlight lang="wikitext" inline>{{Notability}}</syntaxhighlight>, and also <syntaxhighlight lang="wikitext" inline>{{Template:Notability}}</syntaxhighlight>, will both transclude the [[Template:Notability|{{Xtn|[[Template:Notability]]}}]]. Additionally, specific {{Section link|Help:Transclusion|Template parameters|nopage=y}} and {{Section link|Help:Transclusion|Transclusion modifiers|nopage=y}} allow [[Parameter (computer programming)|parameters]] to be passed to templates, alter how transclusion occurs, and therefore the output customized. This is explained in more detail below. === Subpages === [[Wikipedia:Subpages|Subpages]], identifiable by a <code>/</code> prefixed in their page names, are pages related to a 'parent' page (e.g., <code>Namespace:Pagename/Subpagename</code> is a subpage of <code>Namespace:Pagename</code>). This feature is disabled in the Main, File, and MediaWiki namespaces, but not on their corresponding talk namespaces. To transclude subpages: * In general, use <syntaxhighlight lang="wikitext" inline>{{Namespace:Pagename/Subpagename}}</syntaxhighlight>. With exception: ** On the parent page of a subpage, the more specific general syntax mentioned above can be used or simply <syntaxhighlight lang="wikitext" inline>{{/Subpagename}}</syntaxhighlight>. ** For a template namespace page, it is either the general syntax or <syntaxhighlight lang="wikitext" inline>{{Pagename/Subpagename}}</syntaxhighlight>. ** Article subpages are disabled on this wiki, but would otherwise be <syntaxhighlight lang="wikitext" inline>{{:Pagename/Subpagename}}</syntaxhighlight>. * Alternatively, you can also use {{Section link|Help:Transclusion|Template parameters|nopage=y}} and {{Section link|Help:Transclusion|Transclusion modifiers|nopage=y}}. For example, to transclude {{Xtn|[[Template:Like/doc]]}}, you could use <syntaxhighlight lang="wikitext" inline>{{Template:Like/doc}}</syntaxhighlight> or <syntaxhighlight lang="wikitext" inline>{{Like/doc}}</syntaxhighlight>. Note that subpage names are case sensitive, and <syntaxhighlight lang="wikitext" inline>{{Like/Doc}}</syntaxhighlight> would lead to a different page. ===Template parameters<span class="anchor" id="Template transclusion"></span>=== <!-- Keep anchor as used for all section links globally --> {{further|Help:Template#Parameters}} {{for|a quick guide to templates|Help:A quick guide to templates}} The most common use of transclusion on Wikipedia is for [[Help:Template|templates]]. Templates are specially designed pages intended to be included in other pages using either transclusion or [[Help:Substitution|substitution]]. The standard syntax for transcluding a template titled {{Xtn|Template:Pagename}} is <syntaxhighlight lang="wikitext" inline="">{{Pagename}}</syntaxhighlight>. Additionally, many templates support [[Parameter|parameters]], which are variables that allow templates to function in different ways by passing specific values, also termed ''[[Parameter (computer programming)#Parameters and arguments|arguments]]''. Templates may have no parameters, use a fixed number of parameters, or support a variable number of parameters. The number of parameters a template can accept ranges from one to multiple, depending on its design. The exact syntax for using parameters varies by template. However, for a hypothetical template titled {{Xtn|Template:Pagename}} that accepts three parameters, the general format would be: <syntaxhighlight lang="wikitext" inline="">{{Pagename|parameter1|parameter2|parameter3}}</syntaxhighlight> {{shortcut|WP:UNNAMED|WP:POSPARAM|WP:POSITIONAL}} Where each parameter in a template can be substituted with either a <code>value</code> or a {{Para|parameter name|value}} format when used in practice. Notice that each parameter is separated by a [[vertical bar]] (<code>|</code>). Parameters that take the form <code>value</code> are called ''unnamed'' or ''positional parameters'', while those in the form {{Para|parameter name|value}} are known as ''named parameters''. With unnamed parameters, the first, second, and third parameters correspond to {{Para|1}}, {{Para|2}}, {{Para|3}}, respectively, etc., in [[Wikipedia:Template documentation|template documentation]]. Unnamed parameters must be provided in the correct order and are best placed before named parameters.{{Refn|Otherwise using <code>value</code> on its own will not work, and the unnamed parameters must be called using their 'names', such as {{para|1|value}}, if named parameters precede them.|group=lower-alpha}} For example, using the {{Xtn|[[Template:Collapse top]]}} with two unnamed parameters and one named parameter: : {{y}} <syntaxhighlight lang="wikitext" inline="">{{Collapse top|This is the title text|This is a custom warning line|left=true}}</syntaxhighlight> : {{y}} <syntaxhighlight lang="wikitext" inline="">{{Collapse top|left=true|1=This is the title text|2=This is a custom warning line}}</syntaxhighlight> : {{n}} <syntaxhighlight lang="wikitext" inline="" style="background-color:#ffdad3;">{{Collapse top|left=true|This is the title text|2=This is a custom warning line}}</syntaxhighlight> In this case, <code>This is the title text</code> and <code>This is a custom warning line</code> are the values of unnamed parameters {{Para|1}} and {{Para|2}}, while <code>true</code> is the value assigned to the named parameter {{Para|left}}. The last example shows how unnamed parameters should not be used after named parameters without their 'name'. Although this example includes three parameters, {{Xtn|[[Template:Collapse top]]}} can accept a variable number of parameters. For more details, see [[Help:Template]]. Additionally, [[Wikipedia:Template index]] provides a categorized list of templates, including those for mainspace and other namespaces, along with a search function. Template parameters also play a role in the {{section link|#Parametrization method}} of {{Section link|2=Selective transclusion|nopage=y}}, allowing for more dynamic content inclusion. ===Substitution=== {{Main|Help:Substitution}} Transclusion events occur each time the target page is loaded and the template is rendered. A related event is Substitution, where a template call is replaced with its transcluded source content at the time it is invoked in a ''one-time'' inclusion of the content. Unlike transclusion, which continuously updates the target page with changes from the source, substitution results in a ''one-time'' inclusion of the content, meaning that subsequent updates to the source content ''will not'' be reflected in the target page. For example, a template call for <syntaxhighlight lang="wikitext" inline="">{{Pagename}}</syntaxhighlight> with the <syntaxhighlight lang="wikitext" inline="">subst:</syntaxhighlight> prefix results in the substitution template call <syntaxhighlight lang="wikitext" inline="">{{subst:Pagename}}</syntaxhighlight>. When invoked, this template is replaced, also referred to as substituted, with the actual wikitext of the source page at the time of the call, thereby making it a permanent part of the target page.{{refn|group=lower-alpha|In simpler terms, the page is ''published'' or ''saved'', and any future changes to the source page will not affect this substituted content.}} For example, when <syntaxhighlight lang="wikitext" inline="">{{subst:Like}}</syntaxhighlight> is inserted in a page and the changes published, it would substitute that wikitext with the actual wikitext from {{Xtn|[[Template:Like]]}}. In practice, subsequent updates to {{Xtn|[[Template:Like]]}} ''will not'' be reflected in the page it was substituted into. ===Magic words=== {{Main|Help:Magic words}} Magic words are not examples of transclusion. But some have a near identical double curly bracket syntax and similar action to transclusion. For example, <syntaxhighlight lang="wikitext" inline="">{{FULLPAGENAME}}</syntaxhighlight> renders the full [[Wikipedia:Page name|page name]] of any Wikipedia page, for example it returns {{Mono|{{FULLPAGENAME}}}} on this page. Like templates, some magic words can also take parameters, which are separated using a colon (<code>:</code>); for example <syntaxhighlight lang="wikitext" inline="">{{TALKPAGENAME:Help:Transclusion}}</syntaxhighlight> returns {{Mono|{{TALKPAGENAME:Help:Transclusion}}}}. Templates do exist for some magic words, for example [[Template:FULLPAGENAME]]; but these just invoke the related magic word and pass parameters using the verticle bar (<code>|</code>) to the magic word in anycase; for example like <syntaxhighlight lang="wikitext" inline="">{{FULLPAGENAME|value}}</syntaxhighlight>. But magic words parameters are best passed directly by using a colon, which bypasses the unnecessary use of a template call too. For example, <syntaxhighlight lang="wikitext" inline="">{{FULLPAGENAME|value}}</syntaxhighlight> is synonymous with <syntaxhighlight lang="wikitext" inline="">{{FULLPAGENAME:value}}</syntaxhighlight>, where the latter is preferred. ===Transclusion modifiers=== {{See|mw:Help:Magic words#Localization int|mw:Help:Magic words#Transclusion modifiers}} A ''transclusion modifier'' is a type of specialist magic word for altering transclusion in some manner. An example of which is the <code>subst:</code> modifier discussed above in {{Section link|2=Substitution|nopage=y}}. Another example is <syntaxhighlight lang="wikitext" inline="">{{:Notability}}</syntaxhighlight>, where the colon character (<code>:</code>) forces transclusion to the main namespace. There are additional transclusion modifiers such as <code>[[Wikipedia:SAFESUBST|safesubst:]]</code>, <code>[[mw:Help:Magic_words#Localization_int|int:]]</code>, <code>[[mw:Help:Magic_words#Transclusion_modifiers|msg:]]</code>, <code>[[mw:Help:Magic_words#Transclusion_modifiers|msgnw:]]</code>, and <code>[[mw:Help:Magic_words#Transclusion_modifiers|raw:]]</code>. For more details on their usage, see {{slink|mw:Help:Magic words#Transclusion modifiers}}. Also see the modified commands <code>#section:</code>, <code>#section-x:</code> and <code>#section-h:</code> used for labeled section transclusion, see [[Help:Labeled section transclusion]] and the section {{Section link|2=Using the labeled section method|nopage=y}}.
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)