Jump to content

Help:Transclusion: Difference between revisions

m Text replacement - "[[WP:" to "[[wikipedia:WP:"
m Text replacement - "Help:Magic words" to "wikipedia:Help:Magic words"
 
(One intermediate revision by the same user not shown)
Line 56: Line 56:
{{for|a quick guide to templates|Help:A quick guide to templates}}
{{for|a quick guide to templates|Help:A quick guide to templates}}


The most common application of transclusion is the transclusion of [[Help:Template|templates]]. Templates are pages that are written with the prime objective of being included in other pages, either through transclusion or [[Help:Substitution|substitution]]. As shown above, the usual syntax for transcluding a template titled Template:Pagename is <syntaxhighlight lang="wikitext" inline>{{Pagename}}</syntaxhighlight>. However, some templates can also use [[parameter]]s. Parameters are [[Variable (computer science)|variables]] that can be given values (also termed [[Parameter_(computer_programming)#Parameters_and_arguments|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 most common application of transclusion is the transclusion of [[Help:Template|templates]]. Templates are pages that are written with the prime objective of being included in other pages, either through transclusion or [[wikipedia:Help:Substitution|substitution]]. As shown above, the usual syntax for transcluding a template titled Template:Pagename is <syntaxhighlight lang="wikitext" inline>{{Pagename}}</syntaxhighlight>. However, some templates can also use [[parameter]]s. Parameters are [[Variable (computer science)|variables]] that can be given values (also termed [[Parameter_(computer_programming)#Parameters_and_arguments|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:  
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:  
Line 72: Line 72:


===Substitution===
===Substitution===
[[Help:Substitution|Substitution]] has a similar double curly-bracket syntax, and its action is similar to transclusion. When you preview a page with substitution wikitext in it, its action is identical to transclusion. But when you save a page with substitution wikitext in it, it differs in that it substitutes that wikitext with the actual wikitext of the template.  
[[wikipedia:Help:Substitution|Substitution]] has a similar double curly-bracket syntax, and its action is similar to transclusion. When you preview a page with substitution wikitext in it, its action is identical to transclusion. But when you save a page with substitution wikitext in it, it differs in that it substitutes that wikitext with the actual wikitext of the template.  


For example, when <syntaxhighlight lang="wikitext" inline>{{subst:Like}}</syntaxhighlight> is saved, it would substitute that wikitext with the actual wikitext from the [[Template:Like]]. In practice, 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 <syntaxhighlight lang="wikitext" inline>{{subst:Like}}</syntaxhighlight> had already been saved.
For example, when <syntaxhighlight lang="wikitext" inline>{{subst:Like}}</syntaxhighlight> is saved, it would substitute that wikitext with the actual wikitext from the [[Template:Like]]. In practice, 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 <syntaxhighlight lang="wikitext" inline>{{subst:Like}}</syntaxhighlight> had already been saved.


===Magic words===
===Magic words===
[[Help:Magic words|Magic words]] are not examples of transclusion. But some have a similar double curly-bracket syntax and action to transclusion. For example, <syntaxhighlight lang="wikitext" inline>{{FULLPAGENAME}}</syntaxhighlight> renders the [[Wikipedia:Page name|Fullpagename]] of any Wikipedia page. Like templates, some magic words can also take parameters, which are separated using a colon (:); for example <syntaxhighlight lang="wikitext" inline>{{FULLPAGENAME:value}}</syntaxhighlight>.  
[[wikipedia:Help:Magic words|Magic words]] are not examples of transclusion. But some have a similar double curly-bracket syntax and action to transclusion. For example, <syntaxhighlight lang="wikitext" inline>{{FULLPAGENAME}}</syntaxhighlight> renders the [[Wikipedia:Page name|Fullpagename]] of any Wikipedia page. Like templates, some magic words can also take parameters, which are separated using a colon (:); for example <syntaxhighlight lang="wikitext" inline>{{FULLPAGENAME:value}}</syntaxhighlight>.  


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 <syntaxhighlight lang="wikitext" inline>{{FULLPAGENAME|value}}</syntaxhighlight>. But magic words parameters are best passed directly by using a colon, for example like <syntaxhighlight lang="wikitext" inline>{{FULLPAGENAME:value}}</syntaxhighlight>, which bypasses any templates.
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 <syntaxhighlight lang="wikitext" inline>{{FULLPAGENAME|value}}</syntaxhighlight>. But magic words parameters are best passed directly by using a colon, for example like <syntaxhighlight lang="wikitext" inline>{{FULLPAGENAME:value}}</syntaxhighlight>, which bypasses any templates.


===Transclusion modifiers===
===Transclusion modifiers===
As discussed above, with the example <syntaxhighlight lang="wikitext" inline>{{subst:Like}}</syntaxhighlight>, the <code>subst:</code> code alters the transclusion to substitution. This is a ''transclusion modifier'', a type of specialist magic word for altering transclusion in some manner. Another example is <syntaxhighlight lang="wikitext" inline>{{:Notability}}</syntaxhighlight>, where the <code>:</code> (colon character) forces transclusion to the main namespace. There are additional transclusion modifiers such as <code>safesubst:</code>, <code>int:</code>, <code>msg:</code>, <code>msgnw:</code>, and <code>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 [[Help:Labeled section transclusion|labeled section transclusion]].
As discussed above, with the example <syntaxhighlight lang="wikitext" inline>{{subst:Like}}</syntaxhighlight>, the <code>subst:</code> code alters the transclusion to substitution. This is a ''transclusion modifier'', a type of specialist magic word for altering transclusion in some manner. Another example is <syntaxhighlight lang="wikitext" inline>{{:Notability}}</syntaxhighlight>, where the <code>:</code> (colon character) forces transclusion to the main namespace. There are additional transclusion modifiers such as <code>safesubst:</code>, <code>int:</code>, <code>msg:</code>, <code>msgnw:</code>, and <code>raw:</code>. For more details on their usage, see {{slink|mw:wikipedia:Help:Magic words#Transclusion modifiers}}. Also see the modified commands <code>#section:</code>, <code>#section-x:</code> and <code>#section-h:</code> used for [[Help:Labeled section transclusion|labeled section transclusion]].


==Applications of transclusion==
==Applications of transclusion==