Help:Template: Difference between revisions

Content deleted Content added
m Template limits: code comments
mNo edit summary
 
(213 intermediate revisions by 93 users not shown)
Line 1:
{{Short description|Main technical help page on templates}}
{{Redirect-multi|2|H:T|Wikipedia:Template|help regarding tables|Help:Table|content guidelines|Wikipedia:Template namespace}}
{{For-multi|lists of commonly used templates|Wikipedia:Template index|a quick introduction to templates|Help:A quick guide to templates}}
{{Pp-semi-indef}}
{{Wikipedia how to|H:T|WP:TEMPLATE}}
{{forbeginner version|listsHelp:A ofquick commonlyguide usedto templates|Wikipedia:Template messages}}
{{Wiki markup}}
A '''template''' is a Wikipedia page created to be included in other pages. Templates usually contain repetitive material that might need to show up on anya larger number of articles or pages. They are commonly used for [[WikipediaWP:Glossary#Boilerplate text|boilerplate]] messages, standardstandardized warnings or notices, [[Help:Infobox|infoboxes]], [[WP:Navbox|navigational boxes]], and similar purposes. Templates can have parameters so that the same page generates different text on multiple pages that include it.
 
The most common method of inclusion is called [[WikipediaHelp:Transclusion|transclusion]], where the [[WP:wikitext|wikitext]]wiki source of the target page contains a reference to the template, using the <code><nowiki>{{</nowiki>''tnull|{{var|Template&nbsp;name''<nowiki>}}</nowiki></code>}} syntax. Another method is [[Help:Substitution|substitution]], where the content of the template is copied into the wikitextwiki source of the target page, just once, when it is saved.
 
''[[Help:A quick guide to templates]]'' gives a brief introduction to the subject. There is further help from MediaWiki and Wikimedia at [[mw:Help:Templates]], [[m:Help:Template]] and [[mmw:HelpManual:Advanced templates]].
 
==General description==
[[File:Introduction to templates on Wikipedia.webm|thumb|A basic overview of how templates work (8 -minute video)]]
 
Most templates are pages in the [[WP:Template namespace|Templatetemplate namespace]], which means that they have titles in the form "Template:''{{var|XXXX''}}". It is possible, however, to transclude and substitute from any namespace,<ref>{{efn|Namespaces from which transclusion is not allowed are specified on a wiki by the variable <code>[[mw:Manual:$wgNonincludableNamespaces|$wgNonincludableNamespaces]]</refcode>.}} and so some template pages are placed in other namespaces, such as the [[WP:User namespacepages|Useruser namespace]]. Template pages have associated [[WPHelp:talkTalk pagepages|talk pages]].
 
Templates can contain any desired [[wpHelp:wikitextWikitext|wikitext]], including calls to other templates. TheyThere haveis some limited programming capacitiesability: customizable values (calledvia [[#Parameters|parameters]]),; calculation and branchings (using [[Help:Parser functions|parser functions]]); and access to wiki-specific variables ([[Help:Magic words|magic words]]), such as dates, times, and page names. They may also contain tagsmarkup whichto define whichcertain parts of the wikitext arepage to be included whenwhile theother templateparts isare transcluded or substitutednot. This means that thewhen appearanceyou ofdisplay the template page itself, needyou notmay besee themore samethan aswhen thatyou ofdisplay thea page that transcludedincludes contentit (for example, it can contain documentation, categories, etc. for the template).
 
To call a template (cause it to be [[Help:Transclusion|transcluded]] or [[Help:Substitution|substituted]] in the page), a page contains wikitext in double braces. For example, the wikitext {{tnull|under construction}} calls the {{tl|under construction}} template. Sometimes the call includes parameters and looks like <code><nowiki>{{under construction|comment=This is a comment}}</nowiki></code>. Note that template calls are not the only thing for which double braces are used in wikitext.
'''How to do it:''' To transclude a template into an article or page, type <code><nowiki>{{template name}}</nowiki></code> in the wikitext at the place where the template is to appear. The first letter may be indifferently lower- or upper-case.
 
Note that while templates are the usual way transclusion and substitution happen on Wikipedia, they are not the only way.
The prefix <code>Template:</code> before the template name is the default one and need not be included. However, for templates stored in other namespaces, the prefix, such as <code>User:</code>, must be specified. To transclude a page in [[WP:mainspace#Namespace|mainspace]], precede its title with a colon, as <code><nowiki>{{:Page name}}</nowiki></code>.
 
==Using templates==
'''Note:''' Attempting to transclude a template that does not exist produces a [[wp:redlink|red link]], just like linking to any other nonexistent page. Following the link allows one to create that particular template. It is not possible to transclude pages between projects (such as different language Wikipedias)—to use a template on another language project, a copy of the template must be created in that project.
===General===
Using a template is similar to calling a [[Function (computer programming)|function]] in programming. When called, it returns a value. For a template, calling is known as a ''template call'' and the return value is known as the ''expansion'' of the template, which is treated as part of the calling page's source. Like functions, some templates can take parameters that affect their output.
 
Calling a template causes it to be either ''transcluded'' or ''substituted'' in the page that calls it (the ''target page'').
==Usage syntax==
 
[[Wikipedia:Transclusion|Transcluding]] a template means that when MediaWiki <em>displays</em> the page, it treats the template as if it were directly in the page’s source. [[Wikipedia:Substitution|Substituting]] a template differs in that it inserts the content of the template permanently into the target page when it is <em>saved</em>
===Parameters===
and subsequent editors cannot tell that it originated from a template.
{{further|m:Help:Templates#Parameters}}
<!--[[Help:Parameters]] redirects here-->
The basic transclusion syntax given above can be extended by the addition of [[parameter]]s, which are used to control the template's output. The syntax for this is
* <code><nowiki>{{</nowiki>''template name''|''parameter''|''parameter''<nowiki>|...}}</nowiki></code>
where <code>''template name''</code> is the name of the template, and each <code>''parameter''</code> may either contain just a value (these are called ''unnamed parameters'') or be of the form <code>''name''=''value''</code> (''named parameters''). The first, second, third, etc. unnamed parameters will be given the names <code>1</code>, <code>2</code>, <code>3</code>, etc.
 
When you update a template, every page that transcludes it automatically reflects the update when the page is displayed in the future, whereas updating a template has no effect on pages that have previously been saved with the template substituted.
Whitespace characters (spaces, tabs, returns) are stripped from the beginnings and ends of ''named'' parameter names and values, but not from the middle: thus <code><nowiki>{{ ... | myparam = this is a test }}</nowiki></code> has the same effect as <code><nowiki>{{ ... |myparam=this is a test}}</nowiki></code>. This does not apply to ''unnamed'' parameters, where all whitespace characters are preserved.
 
To transclude a template, insert {{tnull|{{var|Template&nbsp;name}}}} at the point where it should appear in the page source. To substitute it, use {{tnull|subst:{{var|Template&nbsp;name}}}}. This wikitext is called a ''template call''.
Which parameters (if any) can or should be passed to a template and how they are to be named depends on the coding of that template. Named parameters can be defined in any order. Superfluous or misnamed parameters will be ignored; undefined parameters will be assigned default values. If a parameter is defined more than once, the last value takes effect.
 
In [[MediaWiki]], the [[wiki software]] that Wikipedia uses, [[Help:Magic words#Variables|variables]] are distinct from templates, though both are referenced by double [[Curly brackets|curly braces]] <code>{{ }}</code> and they both return a value. These references differ in that variables in MediaWiki are always uppercase, while template names follow the same conventions and have the same [[WP:NCHASHTAG|limitations]] as [[Help:Page names|page names]]. For example, they are [[Case sensitivity|case-sensitive]] (except for the first character), [[underscore]]s are parsed as spaces, and template names cannot contain the characters <code><nowiki># < > [ ] | { }</nowiki></code> because they are reserved for [[wiki markup]].
The value of a parameter can be the empty string (pipe or equals sign followed immediately by the next pipe or the closing braces). This is different from omitting the parameter altogether, which leaves it undefined, although templates are often coded so as to behave the same in both cases.
 
The [[number sign]] <code>#</code> is used as a [[URI fragment|fragment identifier]], which identifies a {{em|fragment}} or [[Help:Section|section]] of a page. Although you can use it in a [[WP:LINK|link]] to link to a section of a template page (e.g., [[Template:Portal#Example]]), fragment identifiers have no meaning in a template call and are ignored. For example, {{tnull|Portal{{var|#Location}}|Books}} is the same as {{tnull|Portal|Books}}.
===Calling===
{{Further|mw:Help:Magic words}}
 
The template namespace is the default, so you can leave out the namespace <code>Template:</code> in the template name, and it is conventional to do so. However, you must specify the namespace prefix for templates in other namespaces, such as <code>User:</code>. To transclude a page in [[WP:MAINSPACE|mainspace]], precede its page name with a colon, as <code>{<nowiki />{:{{var|Page name}}}}</code>.
Calling a template is not unlike calling a [[Variable (computer science)|variable]] or a [[Function (computer science)|function]] in a programming language: call it with a reference, and it returns a value (the [[Input/output|output]]). Like functions, some templates accept parameters that change the output.
 
{{A note}} Attempting to transclude a template that does not exist produces a [[WP:Red link|red link]], just like linking to any other nonexistent page. Following the link allows one to create that particular template. It is not possible to transclude templates between projects (such as different-language Wikipedias or MediaWiki) – to use a template on another language project, a copy of the template must be created in that project.
In [[MediaWiki]]—the [[wiki software]] that Wikipedia uses—[[Help:Magic words#Variables|variables]] have a more specific meaning that distinguishes them from templates, but they are both identified by double [[Curly brackets|braces]] {{code|<nowiki>{{ }}</nowiki>}}, and they both return a value.
 
=== Parameters ===
Whereas MediaWiki variable names are all uppercase, template names have the same basic features and [[WP:NCHASHTAG|limitations]] as all [[Help:Page name|page names]]: they are case-sensitive (except for the first character); underscores are [[parsed]] as spaces; and they can't contain any of these characters: {{code|# < > <nowiki>[ ] | { }</nowiki>}} (because those are reserved for [[wiki markup]] and [[HTML]]).
<!-- [[Help:Parameters]] redirects here, so: -->
{{about|template parameters|search parameters|Help:Searching#Parameters|section=yes}}
{{Further|Help:Transclusion#Template parameters}}
{{shortcut|H:PARAMETER|WP:PARAMETER}}
 
The basic transclusion syntax for a template can be further controlled using [[parameters]], which allow you to customize a template’s output. The syntax is <code><nowiki>{{Template name|</nowiki>''parameter''<nowiki>|</nowiki>''parameter''<nowiki>|...}}</nowiki></code>, where <code>{{var|Template name}}</code> is the template’s name, and each <code>{{var|parameter}}</code> can be either a simple value (known as an ''{{dfn|unnamed parameter}}'') or in the form <code>{{var|name}}={{var|value}}</code> (known as a ''{{dfn|named parameter}}''). The first, second, third, etc., unnamed parameters are named <code>1</code>, <code>2</code>, <code>3</code>, etc., so using <code><nowiki>{{Template name|1=value1|2=value2}}</nowiki></code> is equivalent to <code><nowiki>{{Template name|value1|value2}}</nowiki></code>.
The [[number sign]] {{code|#}} is called a [[fragment identifier]] because it denotes a ''fragment'' or section of a document (such as a [[Help:Section|section]] in a Wikipedia article). Although it [[WP:ANCHOR|can be used]] to link to a section of a template page (like [[Template:Portal#Example]]), there is no reason to put a fragment identifier or fragment name in a template reference. In {{code|<nowiki>{{Portal#Location|Books}}</nowiki>}}, for example, the string {{var|#Location}} has no purpose, and is effectively ignored.
 
Each template has specific parameters it can accept, as defined within its code. You can list named parameters in any order in a template call. Extra or misnamed parameters have no effect, while missing parameters cause a default value to be used. If a parameter is repeated, the last defined parameter value is used.
===Substitution===
 
The value of a parameter can be an [[empty string]], such as when the pipe (<code>|</code>) or equals sign is followed immediately by the next pipe or the closing braces. For example, <code><nowiki>{{Template name|1=|2=test}}</nowiki></code> produces the same output as <code><nowiki>{{Template name||2=test}}</nowiki></code>. This is different from not specifying the parameter at all, which results in a default value, although templates are often coded so as to behave the same in both cases.
When a template is [[Help:Substitution|substituted]], its content is [[hard-coded]] in the page rather than [[WP:transclusion|transcluded]]. To learn how and when to substitute a template, see [[Help:Substitution]] to learn [[Help:Substitution#When to use substitution|when]] and how to use substitution.
 
If a template call specifies a parameter which is not defined in the template, it has no effect. Editors sometime specify a parameter they know is not defined in the template &mdash; for example, editors sometimes include a parameter like {{tag|reason|open}} to add a brief explanation within the source as a [[Wikipedia:Manual of Style/Hidden text|hidden comment]]. (But some templates, such as [[Template:Requested move|Requested move]], are programmed to show the reason parameter if provided). Certain templates, especially complex ones like [[Wikipedia:Infobox|infoboxes]], may use the [[Module:Check for unknown parameters|check for unknown parameters module]] to alert editors about any [[:Category:Unknown parameters|unrecognized parameters]] they code by mistake.
==Basic template usage examples==
 
==== Whitespace handling ====
''If you wish to experiment with any of these, please use the [[Template:Template sandbox|template sandbox]], your user page or sandbox''
 
Leading and trailing [[Wikipedia:Whitespace|whitespace]] (including line breaks) around {{em|named}} parameters and values is [[Whitespace collapsing|collapsed]] automatically, but spaces in the middle of the value are kept. For instance, <code><nowiki>{{ ... | myparam = this is a test }}</nowiki></code> has the same output as <code><nowiki>{{ ... |myparam=this is a test}}</nowiki></code>. However, with {{em|unnamed}} parameters, all whitespace is retained as preserved in the output.
An example of a very simple template can be found at [[Template:Lambda]], which expands out to place the lambda symbol ( λ) at that point in the text. A programmer would say that the template ''returns'' the lambda symbol ( λ).
 
The collapsing of line breaks around parameters can be used to [[Wikipedia:Template namespace#Readability of the code|improve the readability of a template call]] with many parameters by placing each parameter specification in its own line.
Click on [[Template:Lambda]] the click on the "Edit source" tab to see the template code (its wikitext). The "active" part of that code, called the ''expansion'' of the template, is the single word <code>&amp;lambda;</code>. (You will recall that <code>&amp;lambda;</code> is the [[List_of_XML_and_HTML_character_entity_references|character entity used in HTML]] for the Greek letter ( λ).) The remainder of the wikitext is enclosed between {{tag|noinclude}} tags so it is displayed on the template page itself but will not be displayed when the template is used (or called) on another page.
 
==== Variable length parameter lists ====
To transclude the Template:Lambda onto another page (i.e. to use it on another page), type {{tlc|lambda}} (or {{tlc|Lambda}}—the case of the first letter is not significant) into the wikitext of the target page and 'show preview'. The page will be displayed with the ''template call'' were replaced by the expansion of the template. i.e. as if the wikitext actually contained <code>&amp;lambda;</code> at that point. The displayed page will therefore contain the text "λ".
In MediaWiki, templates cannot automatically handle an unknown or unlimited number of parameters. Each possible parameter usually has to be predefined in the template code. For example, a template might be set up to use three specific parameters, such as <code>1</code>, <code>2</code>, and <code>3</code>. If someone includes additional parameters beyond those, they will not affect expansion of the template.
 
However, there are some ways to work around this:
For example, type "<code>The 11th letter of the Greek alphabet is the lambda ({{tlf|lambda}})</code>" and you will see "The 11th letter of the Greek alphabet is the lambda ({{lambda}})". You can use templates without knowing the details of their code—you only need to remember what result they produce (this is usually described on the template page).
 
*Setting a limit: You can write the template to handle a fixed number of parameters by manually specifying each one (e.g., up to 10 or 20 parameters).
Another way to use this template is to [[Help:Substitution|substitute]] it. If you type "<code>The 11th letter of the Greek alphabet is the lambda ({{tls|lambda}})</code>" and save the page, you will again see "The 11th letter of the Greek alphabet is the lambda (λ)". However this time, if you look again at the saved wikitext, you will see that the template calls really were replaced by the expansion of the template when you saved the page. The link between the output text and the template is now broken, and the output will not be affected by changes which might be made to the template at some future time (as it would be in the case of transclusion).
 
*Using templates or [[Wikipedia:Lua|modules]]: For cases needing a flexible number of inputs, templates can use Lua modules or helper templates (like {{mfl|separated entries|main}} or {{tl|separated entries}}). These helper tools provide more advanced handling, such as counting or iterating through parameters, enabling the use of multiple inputs without setting an exact number.
==={{anchor|Parameters}} Examples with parameters===
 
However, modules can bypass this limitation. For simpler cases, the separated entries module expands all sequential parameters and lets you set custom delimiters. For more advanced usage, the {{mfl|params}} module enables counting, listing, mapping, filtering, and handling a variable number of parameters without prior knowledge of the exact number.
An example of a template that takes parameters is the template {{tl|about}}. Try typing <code><nowiki>{{about|how to use templates|how to use modules|Help:Module}}</nowiki></code> in the sandbox—it will produce the following text:
{{about|how to use templates|how to use modules|Help:Module}}
The template {{tl|about}} uses three unnamed parameters in the example above, but the same template can also be used with different numbers of parameters to give slightly different results, as explained in the documentation on the template page. For example, <code><nowiki>{{about||how to use modules|Help:Module}}</nowiki></code>.
Note the usage of an empty parameter—in this instance, the consecutive pipes mean that the first parameter that was "passed" to the template is an empty string, which in this template will cause it to omit the initial "about" sentence. This produces:{{about||how to use modules|Help:Module}}
 
Templates that accepts an open number of parameters are often collected under [[:Category:Variadic templates]].
Other templates, particularly more complex ones, take named parameters or a mixture of named and unnamed ones. A simple example is [[Template:Payoff matrix]], used to generate a 2-by-2 grid. Type:
:<code><nowiki>{{payoff matrix | UL = 5 | UR = 7 | DL = 2 | DR = 9 | Name = Example usage }}</nowiki></code>
{{payoff matrix | UL = 5 | UR = 7 | DL = 2 | DR = 9 | Name = Example usage }}
to produce the grid you can see on the right.
 
===Examples===
See the [[Template:Payoff matrix|template page]] for more possibilities. Notice that the template is used here without defining all its possible parameters—undefined parameters are given default values.
 
{{A note}} If you wish to experiment with any of these, you can use the [[Template:Template sandbox|template sandbox]] or your user page or sandbox. You can try out your template with [[Special:ExpandTemplates]].
The spaces around the equal signs and before and after the parameters are used only for clarity—they are not needed and are ignored when the template is evaluated (although this is not the case with unnamed parameters). However parameter names are fully case sensitive—for example, it is not possible to replace "DR" by "dr" or "dR" in the above example. Parameters with names that are not used by the template are simply ignored.
 
An example of a very simple template can be found at [[Template:TM]], which expands to wikitext that places the trademark symbol (™), linked to the [[trademark]] article, at that point in the displayed page. A programmer would say that the template "returns" the trademark symbol link wikitext.
Examining the source code of the template shows the standard table mark up with some extra triple bracket entities representing the parameters:
 
<source lang=moin>
Display [[Template:TM]] (by clicking on the foregoing link), then click on the "Edit" tab to see the template code (its page source). The active part of that code, which becomes the expansion of the template when it is transcluded, is the single link wikitext <code><nowiki>[[Trademark|™]]</nowiki></code>. The remainder of the page source is enclosed between {{xtag|noinclude}} tags, so it shows up when you display the template page itself but not when you display a page that calls the template.
{| id="Payoff matrix" style="background:white; float: {{{Float|right}}}; clear:right; text-align:center;" align={{{Float|right}}} cellspacing=0 cellpadding=8 width={{{Width|225}}}
 
|-
To transclude Template:TM onto another page (i.e., to use it on another page), type {{tlx|TM}} into the source of that page (the target page) and click {{Button|Show preview}}. The page will be displayed with the template call replaced by the expansion of the template, as if the wikitext actually contained <code><nowiki>[[Trademark|™]]</nowiki></code> at that point. The displayed page will therefore contain the wikilink "[[Trademark|™]]".
|style="width:33%; "|
 
|style="width:33%; border-bottom: solid black 1px;"| {{{2L|Left}}}
For example, type <code>The trademark symbol is {{tl|TM}}</code> and you will see "The trademark symbol is {{TM}}" when previewing the page or after saving the change.
|style="width:33%; border-bottom: solid black 1px;"| {{{2R|Right}}}
 
|-
The other way to use a template is to [[Help:Substitution|substitute]] it. If you type <code>The trademark symbol is {{tls|TM}}</code> and preview or save the page, you will see "The trademark symbol is [[Trademark|™]]" just as with the transclusion example above. But if you save the page and then look again at the saved page <em>source</em>,{{efn|There is no way to preview the effect on the page source of substitution without saving the page}} you will see <code>The trademark symbol is <nowiki>[[Trademark|™]]</nowiki></code>, because the template call was replaced by the expansion of the template when you saved the page. There is no ongoing connection to the template call; no one can tell by looking at the page source that you didn't just type <code>The trademark symbol is <nowiki>[[Trademark|™]]</nowiki></code> and if the {{tl|TM}} template changes (or ceases to exist), your page will continue to display as it does now. (In contrast, in the transclusion example above, if the {{tl|TM}} template subsequently changes, your page may then display differently).
|style="border-right: solid black 1px; text-align: right; "| {{{1U|Up}}}
 
|style="border-right: solid black 1px; border-bottom: solid black 1px; background:{{{ULc|white}}}; font-size:120%; "| {{{UL|0, 0}}}
===={{anchor|Parameters}} Examples with parameters====
|style="border-right: solid black 1px; border-bottom: solid black 1px; background:{{{URc|white}}}; font-size:120%; "| {{{UR|0, 0}}}
 
|-
An example of a template that takes parameters is the template {{tlx|about}}. Try typing {{tnull|about|how to use templates|how to use modules|Help:Lua}} in the sandbox—it will produce the following text:
|style="border-right: solid black 1px; text-align: right; "| {{{1D|Down}}}
{{about|how to use templates|how to use modules|Help:Lua}}
|style="border-right: solid black 1px; border-bottom: solid black 1px; background:{{{DLc|white}}}; font-size:120%; "| {{{DL|0, 0}}}
The template {{tlx|about}} uses three [[unnamed parameter]]s (also called positional parameters) in the example above, but you can call the same template with different numbers of parameters to give slightly different results, as explained in [[Template:About/doc|the template's documentation]]. For example, {{tnull|about|&#124;how to use modules|Help:Lua}}. Note the usage of an empty parameter—in this instance, the consecutive pipes mean that the first parameter specified is an empty string, which in this template will cause it to omit the initial "about" sentence. This produces: {{about||how to use modules|Help:Lua}}
|style="border-right: solid black 1px; border-bottom: solid black 1px; background:{{{DRc|white}}}; font-size:120%; "| {{{DR|0, 0}}}
 
|-
A simple example of a template that has named parameters is [[Template:Payoff matrix]], used to generate a 2-by-2 grid. For example:
|style="font-size: 90%;" colspan=3 |''{{{Name|{{PAGENAME}}}}}''
{{Markup|<nowiki>{{payoff matrix | UL = 5 | UR = 7 | DL = 2 | DR = 9 | Name = Example usage }}</nowiki>|{{payoff matrix | UL = 5 | UR = 7 | DL = 2 | DR = 9 | Name = Example usage }}}}
|}</source>
 
See the [[Template:Payoff matrix|template page]] for more possibilities. Notice that the template is called here without specifying all its possible parameters, so undefined parameters are given default values.
The entity <code><nowiki>{{{2L|Left}}}</nowiki></code> means use the named parameter 2L, or the text 'Left' if the parameter is not present in the call.
 
==Usage hints=Hints and workarounds===
The following points may be worth noting when using templates:
* Templates are not the only method of [[Help:Transclusion|transclusion]], in some cases, other methods such as [[WP:SELECTIVETRANSCLUSION|selective transclusion]] are more appropriate.
* An unnamed parameter cannot contain an ordinary equals sign, as this would be interpreted as setting off a named parameter. (This does not apply if the equals sign comes within another template call or other item which the parser handles separately.) To pass an equals sign in an unnamed parameter (for example in a [[URL]] with key/value pairs), replace the equals sign with the special template {{tlx|{{=}}}}, which returns an equals sign that will not be specially interpreted. Another method is to replace the unnamed parameter (and any subsequent unnamed parameters) with named parameters—the first unnamed parameter is equivalent to a named parameter with the name "1" and so on. So to call template {{tl|done}} with "a=b" as the literal value for the first parameter, type either <code><nowiki>{{done|a{{=}}b}}</nowiki></code> or <code><nowiki>{{done|1=a=b}}</nowiki></code>.
* {{anchor|Equals}}An unnamed parameter (positional parameter) value cannot contain an ordinary equals sign, as this would be interpreted in the parameter specification as a named parameter (with the equals sign separating the name from its value).{{efn|This does not apply if the equals sign comes within another template call or other item which the parser handles separately.}}
* Similarly, it is not possible to use an ordinary pipe character | in template parameters, as it will be interpreted as a separator. (Again, this does not apply if it comes within another separately parsed item, such as a piped wikilink.) This time the problem can be solved by using the [[mw:Help:Magic words#Other|magic word]] {{tnull|!}} in place of the pipe, or (if the pipe is not intended to be parsed specially at a higher level) using the [[List of XML and HTML character entity references|HTML entity]] <code>&amp;#124;</code>.
** To specify an unnamed parameter including an equals sign (for example in a [[URL]] with [[name–value pair]]s), replace the equals sign with the [[mw:Help:Magic words#Other|magic word]] {{tlx|{{=}}}}, which expands to an equals sign that will not be interpreted.
* Remember that whitespace characters (spaces, tabs, carriage returns and line feeds) are not automatically stripped from the start and end of unnamed parameters (as they are from named parameters). Including such characters (or any other non-visible characters in any parameters) may in some cases affect the template's behaviour in unexpected ways. (Template designers can use {{tl|Strip whitespace}} to remove unwanted whitespace in unnamed parameters.)
** Another method is to explicitly specify the positional parameters. The first unnamed parameter is named "1" and so on. To call template {{tl|done}} with <code>a=b</code> as the literal value for the first parameter, type either <code><nowiki>{{done|a{{=}}b}}</nowiki></code> or <code><nowiki>{{done|1=a=b}}</nowiki></code>.
* In documentation and discussions it is often convenient to be able to produce the template call syntax, with a link to the template in question, but without actually calling the template. This can be done easily using the "{{tl|tl}}" template (the ''template link'' template). For example, "<code><nowiki>{{tl|Example}}</nowiki></code>" produces "{{tl|Example}}". There is an extended version, {{tl|tlx}}, which also supports parameters.
* {{anchor|Pipe}}Similarly, it is not possible to use an ordinary pipe character <code>&#124;</code> in a template parameter specification, as it would be interpreted as separating one parameter specification from another.{{efn|Again, this does not apply if it comes within another separately parsed item, such as a piped wikilink.}} This problem can similarly be solved by using the magic word {{tlx|!}} in place of the pipe, or—if the pipe is not intended to be parsed at a higher level—using the [[List of XML and HTML character entity references|HTML entity]] <code>&amp;#124;</code>. Alternatively, for embedding [[Help:Table|wikitables]] in templates, you may use {{tlx|Wikitable}} to avoid excessive {{tlx|!}}.
* When a template is changed (when the template or one of its subtemplates is edited), the change will be reflected on all pages on which the template is transcluded. However the change may not become visible on all pages immediately—a previously cached version of a page, based on the previous version of the template, may continue to be displayed for some time. Use the [[Help:Purge|purge]] function to force a page to be displayed using the latest versions of templates. (This includes the template page itself, if it contains usage examples.)
* Remember that whitespace characters (spaces, tabs, carriage returns, and line feeds) are not automatically stripped from the start and end of unnamed parameters, unlike with named parameters. Including such characters (or any other non-visible characters in any parameters) may in some cases affect the template's behavior in unexpected ways. (Template designers can use {{tl|Trim}} to remove unwanted whitespace in unnamed parameters).
* In documentation and discussions, it is customary to put the name of a template in double braces to emphasize the reference to a template (for example, use {{tl|Trim}} as the name of Template:Trim). If you just type <code><nowiki>{{Trim}}</nowiki></code> in the source page, that will of course call the template, so to make it easy to display the name with the braces, and also make the name a link to the template for the reader's convenience, there is the {{tl|tl}} template (the "'''t'''emplate '''l'''ink" template). For example, {{tnull|tl|Example}} produces {{tl|Example}}. There are various other [[Template:Template-linking templates|template-linking templates]] available with other functions.
* When an editor changes a template (by editing the template or one of its subtemplates), the change will ultimately be reflected any time any page that transcludes that template is subsequently displayed. However, the change may not become visible on all pages immediately; a previously cached version of a page, based on the previous version of the template, may continue to be displayed for some time. Use the [[WP:Purge|purge]] function to force a page to be displayed using the latest versions of templates—including on the template page itself, if it contains usage examples.
* When viewing old versions of pages, remember that templates will be transcluded as they are now, not necessarily as they were when the old page version was active.
* To list all pages ontothat whichtransclude a template is transcluded, use the [[WPHelp:What links here|What links here]] link on the page when you display the template page. (ThisNote that this will {{em|not}} include pages where the template has been substituted, as there is no record of substitutions.)
* To get a list of templates transcluded on a page, clickbring "Edit",up the edit page and find the list below the edit window. This list also includes the sub-templatessubtemplates used by the templates that are directly transcluded. To get such a list for a page section, an old version of the page,{{efn|For oran your newly editedold version, priorthe tosubtemplate saving,tree clickwill "Showbe preview"constructed onaccording to the appropriatetemplates' editcurrent pagestate.}} (Foror anyour oldnewly edited version, theprior subtemplateto treesaving, willclick be{{Button|Show constructedpreview}} according toon the templates'appropriate currentedit statepage.)
* There are limits to the number and complexity of the templates that an article may have. See the "[[#Expand limits|§ Expand limits]]" section for help in resolvingwith this.
* If you'd likewant the template to leave a [[WP:~|time stamp or signature]], you can write <code>&lt;noinclude>&lt;nowiki>&lt;/noinclude><nowiki>~~~~~</nowiki>&lt;noinclude>&lt;/nowiki>&lt;/noinclude></code>., Butbut this willworks only work ifwhen you <em>substitute</em> the template. If you <em>transclude</em> it, you'll just get <nowiki>~~~~~</nowiki>.
* To improve readability, programmers usually programmers like to split the code with newlines and indent it. Unfortunately, [[MediaWiki]] software does not allow this functionality andtechnique; in many instances, these purpose-built newlines are treated by the softwareMediaWiki as content. One possible workaround is to add <code>&lt;!--</code> before each newline character and <code>--></code> after it, which produces an [[HTML comment]].
 
==Creating and editingWriting templates==
<!--[[Help:Subtemplates]] redirects here.-->
 
===Process===
Templates are created and edited in much the same way as any other page: choose an appropriate name, navigate to that page, then click the Edit tab or create a new page as needed. As mentioned above, templates are normally placed in the [[WP:Template namespace|Template namespace]], though templates intended for your own personal use or for experimentation can be created in your own [[WP:user space|user space]]. Anything that can be included on a normal page or article can be included on a template, including other templates (called ''subtemplates''). Templates often make use of programming features—parameters, parser functions and other [[Help:Magic words|magic words]]—which allow the transcluded content to vary depending on context. There are also special tags to control which information is transcluded and which is not.
Templates are just Wikipedia pages. They are created, deleted, and edited in much the same way as any other page.
 
====Creating====
Before creating a template, do a quick search for existing templates (e.g. by exploring [[:Category:Wikipedia templates]]) to see if there's already a template that does what you want, or a similar template whose code can be copied and modified (or left in place and expanded). Look for generic templates on which the new template can be based (for example, [[WP:navbox|navbox]] templates can be easily created by calling the generic [[Template:Navbox]]).
 
To create a template, choose an appropriate name, navigate to that page, then click the "Edit" tab or create a new page as needed.
There is no hard rule about what name to choose for a template—make it short but reasonably descriptive. If similar templates exist, try to follow a consistent naming pattern. Templates can be renamed without breaking existing transclusions, provided a redirect to the new template name is left behind.
 
Templates are normally placed in the [[WP:Template namespace|template namespace]], though you can place a template intended for your own personal use or for experimentation in your own [[WP:User pages|user space]].
Be extremely careful when editing existing templates—changes made can affect a large number of pages, often in ways you might not expect. For this reason many high-use templates are [[WP:protection|protected]] against editing except by [[WP:administrator|administrators]] and [[WP:template editor|template editors]] (other editors can propose changes on the talk page). Some templates offer a sandbox and [[Wikipedia:Template test cases|test cases]] for experimentation.
 
Before creating a template, do a quick search for existing templates (such as by exploring [[:Category:Wikipedia templates]]) to see if there is already a template that does what you want or a similar template whose code can be copied and modified (or left in place and expanded). Look for generic templates on which the new template can be based; for example, you can create a [[WP:Navbox|navbox]] template easily by creating a brief template that calls the generic [[Template:Navbox]].
To propose the deletion or merger of unused or inappropriate templates or templates that can easily be merged, go to [[WP:Templates for discussion|Templates for discussion]] (TfD).
 
There is no hard rule about what name to choose for a template—make it short but reasonably descriptive. The [[Wikipedia:Template namespace|naming guideline]] says: "Template function should be clear from the template name". If similar templates exist, try to follow a consistent naming pattern. You can rename a template without breaking existing [[Help:Transclusion|transclusions]] (what is called ''breakage'') by leaving a [[WP:Redirect|redirect]] to the new template name.
 
====Modifying====
Edit a template the same way as any other page: navigate to the template and click the "Edit" tab.
 
Be extremely careful when editing existing templates—changes made can affect a large number of pages, often in ways you might not expect. For this reason many high-use templates are [[WP:Protection policy|protected]] against editing except by [[WP:Administrators|administrators]] and [[WP:Template editor|template editors]]; other editors can propose changes on the talk page. Some templates offer a [[WP:Template sandbox and test cases|sandbox and test cases]] for experimentation.
 
====Deleting====
Unused or inappropriate templates should be deleted. Templates that can be easily merged into another should be merged.
 
To propose the deletion or merger of a template, go to [[WP:Templates for discussion|Templates for discussion]] (TfD).
 
===Coding a template===
Anything that can be included on a normal page or article can be included on a template, including other templates (called ''{{dfn|subtemplates}}''). Templates often make use of programming features—parameters, parser functions, and other [[Help:Magic words|magic words]]—which allow the transcluded content to vary depending on context. There are also special tags to control which information is transcluded and which is not.
 
==== Metatemplates ====
Various [[Help:Metatemplating|metatemplates]] and metamodules exist to help accomplish common template tasks. They are called like normal templates and [[Help:Modules|modules]], but they serve a purpose that makes writing templates easier. See {{Cl|Wikipedia metatemplates}} and {{Cl|Template metamodules}} for a list of those templates and modules.
 
===Handling parameters===
In template code, the value of a parameter is represented by items enclosed between {{em|triple}} braces, which is a ''parameter reference''.
* The code <code><nowiki>{{{xxx}}}</nowiki></code> expands to the value of the parameter named "xxx".
* The codes <code><nowiki>{{{1}}}</nowiki></code>, <code><nowiki>{{{2}}}</nowiki></code>, and so on are expanded to the first, second, and so on unnamed parameters. (Note that an unnamed parameter can alternatively be specified in a template call as an equivalent named parameter named "1", "2", etc.).
 
If a parameter is not specified in the template call, then the parameter reference is not replaced with anything -- it is expanded literally; this means that if the template call does not specify the parameter "xxx", the wikitext <code><nowiki>{{{xxx}}}</nowiki></code> inside the template expands to literally ''<nowiki>{{{xxx}}}</nowiki>'' (not the null string you may have expected). You can get a more useful behavior by specifying a default value in the parameter reference. Do this with the ''pipe syntax'': <code><nowiki>{{{xxx|dflt}}}</nowiki></code> specifies the default value <code>dflt</code> for the named parameter "xxx", and <code><nowiki>{{{1|dflt}}}</nowiki></code> specifies the default value <code>dflt</code> for the first unnamed parameter. Most often, one specifies a null default value, such as <code><nowiki>{{{1|}}}</nowiki></code> or <code><nowiki>{{{xxx|}}}</nowiki></code>.
The values of the parameters which can be fed to a template are represented in the template code by items enclosed between ''triple'' braces:
* the code <code><nowiki>{{{xxx}}}</nowiki></code> will be replaced by the value of the parameter named ''xxx''. these are known as ''named parameters'' .
* the codes <code><nowiki>{{{1}}}</nowiki></code>, <code><nowiki>{{{2}}}</nowiki></code> etc. will be replaced by the first, second etc. ''unnamed parameter'' (or the value of a parameter named ''1'', ''2'', etc.); these are sometimes known as ''positional'' parameters
 
If a parametercall is not assignedsets a value, then no replacement will take place—this means that if no value is passed for parameter ''xxx'',to the valueempty ofstring the expressionlike <code><nowiki>{{{Template name|xxx}=}}</nowiki></code> insidethen the template will literally be ''<code><nowiki>{{{xxx|OK}}}</nowiki>''</code> notwill produce the 'blank'empty youstring mayand havenot expected.the Adefault morevalue intuitive"OK". behaviourMany canusers bewill achievedexpect bythat specifyingan defaultempty parameter values.gives Thisthe issame doneresult withas omitting the ''pipeparameter. You can syntax''achieve this with: <code><nowiki>{{#if:{{{xxx|dflt}}}|{{{xxx}}}|OK}}</nowiki></code>. specifiesThis thesays: defaultIf value<code>xxx</code> ''dflt''is forassigned thea namednon-empty parametervalue ''xxx'',then anduse <code><nowiki>{{{1|dflt}}}</nowiki>xxx</code>, specifiesotherwise use "OK". If the default value ''dflt'' foris the firstempty unnamedstring parameter.then Mostyou often,only this is usedhave to specify null default values (<code><nowiki>{{{1|}}}</nowiki></code> orwrite <code><nowiki>{{{xxx|}}}</nowiki></code>).
 
You can use default parameter values to effect a parameter alias:
Note the default text must be real text: that you cannot assign another parameter as the default. It will simply return the 'name' of the parameter as text. <!-- For example, suppose the template 'Template:Hello' is <code>{{{1|param}}}</code>, and is called with <code><nowiki>{{hello|param=world}}</nowiki></code>. Parameter '1' does not exist, so it will call the default. The text returned is the "param" or what would be expected to be the parameter name, not the parameter's assignment "world". This would be best implemented by a sequence of if [[mw:Help:Extension:ParserFunctions|parser statements]].-->
<!--For Alsoexample, noteif thatparameters if"text" aand template"message" isare callednames withfor the same parameter, specifiedwhich ascan blankalso (e.g.be <code>&#123;&#123;Example|&#125;&#125;</code>),specified as the defaultonly for theunnamed parameter, willthen notrefer appear. If that is undesired one can check ifto the parameter exists throughwith the parser code<code><nowiki>{{#if:{message|{{1|}}}{text|{{{1|}}}}}}}|default}}</nowiki></code> instead. ThisIf the template call specifies more than one of those parameters, "message" will producehave thepriority, textfollowed by "defaulttext", evenand iffinally by the first unnamed parameter. isSo specifiedif asa empty.--template call specifies parameters <code>|message=A|text=B|C</code>, the above wikitext expands to <code>A</code>.
 
Because of the multiple meanings of double-brace and triple-brace syntax in wikitext, expressions can sometimes be ambiguous. It may be helpful or necessary to include spaces to resolve such ambiguity. For example, <code><nowiki>{{ {{{xxx}}} }}</nowiki></code> or <code><nowiki>{{{ {{xxx}} }}}</nowiki></code>, rather than typing five consecutive braces, may be more human-readable. But watch out for unwanted whitespace appearing in the template expansion.
 
Parameter references do not get expanded when they are wrapped in {{xtag|nowiki}} tags.
 
====Example====
The parameter usage example above refers to the {{tl|payoff matrix}} template. Here is the code in the template that implements those parameters:
 
<syntaxhighlight lang="wikitext">
{| id="Payoff matrix" style="background:white; float: {{{Float|right}}}; clear:right; text-align:center;" align={{{Float|right}}} cellspacing=0 cellpadding=8 width={{{Width|225}}}
|-
|style="width:33%; "|
|style="width:33%; border-bottom: solid black 1px;"| {{{2L|Left}}}
|style="width:33%; border-bottom: solid black 1px;"| {{{2R|Right}}}
|-
|style="border-right: solid black 1px; text-align: right; "| {{{1U|Up}}}
|style="border-right: solid black 1px; border-bottom: solid black 1px; background:{{{ULc|white}}}; font-size:120%; "| {{{UL|0, 0}}}
|style="border-right: solid black 1px; border-bottom: solid black 1px; background:{{{URc|white}}}; font-size:120%; "| {{{UR|0, 0}}}
|-
|style="border-right: solid black 1px; text-align: right; "| {{{1D|Down}}}
|style="border-right: solid black 1px; border-bottom: solid black 1px; background:{{{DLc|white}}}; font-size:120%; "| {{{DL|0, 0}}}
|style="border-right: solid black 1px; border-bottom: solid black 1px; background:{{{DRc|white}}}; font-size:120%; "| {{{DR|0, 0}}}
|-
|style="font-size: 90%;" colspan=3 |''{{{Name|{{PAGENAME}}}}}''
|}</syntaxhighlight>
 
The entity <syntaxhighlight lang="wikitext" inline>{{{2L|Left}}}</syntaxhighlight> instructs the template to use the value of the named parameter <code>2L</code> or the text <code>Left</code> if the parameter is not specified in the call.
Because of the multiple uses of double-brace and triple-brace syntax, expressions can sometimes be ambiguous. It may be helpful or necessary to include spaces to resolve such ambiguity, for example by writing <code><nowiki>{{ {{{xxx}}} }}</nowiki></code> or <code><nowiki>{{{ {{xxx}} }}}</nowiki></code>, rather than typing five consecutive braces. However, watch out for unwanted whitespace appearing in template expansions.
 
; ====Special case{{colon}}: Parametersparameters within an XML-style opening tag====
ParametersParameter do not get expanded when they are wrapped in {{tag|nowiki}} tags. They howeverreferences aren't expanded either if placed within the actualinside [[XML]]-style opening tagtags. Thus, the following will not work within a template:
: *{{!mxt|<nowiki><ref name={{{param}}}> Smith, Adam (1776)...</ref></nowiki>}}
because the parameter is not expanded. Instead, you can however use the <code><nowiki>{{#tag:}}</nowiki></code> [[WP:PF|parser function]], which foris—for example is usedexample—used in {{tlx|sfn}} to generate the {{tag|ref}} element; ''(see also [[{{section link|Help:Magic words#|Formatting]])''}}. Therefore, the following example will work:
: *{{mxt|<nowiki>{{#tag:ref | MarxSmith, KarlAdam (18481776)... | name={{{param}}} }}</nowiki>}}
 
; ====Caution{{colon}} : Overextendingoverextending URLs====
If a parameter's value is (or ends with) a [[URL]], check whether it is displayed in Wikipedia with the link overextending by one or more characters after the URL so that clicking the link causes an error or failure. Ensure that, after processing by the software, a soft space (not [[non-breaking space|hard or nonbreaking]]) follows the URL, regardless of whether you or a user supplied the URL, or it was generated by automated processing. Possibly, the source code could contain or generate a space that is discarded in the processing or there might not be any space there. Correct the source code, perhaps by forcing a soft space to appear after the URL. The {{Tl|Spaces}} template may be useful.
This could happen because the source code does not have a space after the URL or it contains or generates a space that is discarded in the processing. Ensure that in the template expansion a soft space ({{em|not}} a [[Non-breaking space|hard or non-breaking space]]) follows the URL, regardless of whether you or a user supplied the URL or whether it was generated by automated processing. The {{tlx|spaces}} template may be useful.
 
===System variables and conditional logic===
 
Template code often makes use of the variables and parser functions described at [[Help:Magic words]], in order to make the template's behaviourbehavior depend on the environment in which it is included (such as the current time or namespace). orParser onfunctions thecan parameterbe valuesused thatfor aresome passedarithmetic tocalculations it.and Theystring canmanipulations alsoon bevariables usedand forparameter arithmetical calculationsvalues, but certain standard programming features such as loops and variable assignment are not avalableavailable. Full string manipulation is also not available; (some templates providing such functionalityfunction have been created, but they are inefficient and imperfect).
 
Some of the most oftenfrequently used variables and functions are listed below. For more, see [[Help:Magic words]], and the fuller documentation at the MediaWiki pages [[mw:Help:Magic words]] and [[mw:Help:Extension:ParserFunctions]].
 
{| class="wikitable" style="text-align:center;" width="80100%"
|+Examples of core parser functions
! width="30%" | Description !! width="40%" | Textwiki enteredsource !! width="30%" | ResultDisplayed text
|-
| Uppercasing text
| <nowikisyntaxhighlight lang="wikitext" inline>{{uc: Heavens to BETSY! }}</nowikisyntaxhighlight>
| {{uc: Heavens to BETSY! }}
|-
| Lowercasing text
| <nowikisyntaxhighlight lang="wikitext" inline>{{lc: Heavens to BETSY! }}</nowikisyntaxhighlight>
| {{lc: Heavens to BETSY! }}
|-
| Getting a namespace name
| <nowikisyntaxhighlight lang="wikitext" inline>{{NS: 1 }}</nowikisyntaxhighlight>
| {{NS: 1 }}
|-
| Getting a Wikipedia URL
| <nowikisyntaxhighlight lang="wikitext" inline>{{fullurl: pagename }}</nowikisyntaxhighlight>
| {{fullurl: pagename }}
|}
 
The ParserFunctions extension provides more programming-oriented parser functions.:
 
{| class="wikitable" style="text-align:center;" width="80100%"
|+Examples of extension parser functions
! width="30%" | Description !! width="40%" | TextWiki enteredsource !! width="30%" | ResultDisplayed text
|-
| rowspan="2" | Testing for equality between two strings (or parameters). If the first two parameters are equal, the third parameter is returned, otherwise the fourth parameter is returned.
| <nowikisyntaxhighlight lang="wikitext" inline>{{#ifeq: yes | yes | Hooray...! | Darn...! }}</nowikisyntaxhighlight>
| {{#ifeq: yes | yes | Hooray...! | Darn...! }}
|-
| <nowikisyntaxhighlight lang="wikitext" inline>{{#ifeq: yes | no | Hooray...! | Darn...! }}</nowikisyntaxhighlight>
| {{#ifeq: yes | no | Hooray...! | Darn...! }}
|-
| Testing whether a string (or parameter) contains anything (other than whitespace). If it does, the second parameter is returned, otherwise the third parameter is returned.
| <nowikisyntaxhighlight lang="wikitext" inline>{{#if: {{{param|}}} | Hooray...! | Darn...! }}</nowikisyntaxhighlight>
| {{#if: {{{param|}}} | Hooray...! | Darn...! }}
|-
| [[Help:Calculation|Making a calculation (mathematics)]] <br />[area of circle of radius&nbsp;4, to 3&nbsp;decimal places]
| <nowikisyntaxhighlight lang="wikitext" inline>{{#expr: ( pi * 4 ^ 2 ) round 3 }}</nowikisyntaxhighlight>
| {{#expr: ( pi * 4 ^ 2 ) round 3 }}
|-
| [[Help:Calculation|Testing the result of a calculation]]. If the expression is true or non-zero, the second parameter is returned, otherwise the third parameter is returned.<br />[is 1230 even or odd?]
| <nowikisyntaxhighlight lang="wikitext" inline>{{#ifexpr: 1.23E+3 mod 2 | Odd | Even }}</nowikisyntaxhighlight>
| {{#ifexpr: 1.23E+3 mod 2 | Odd | Even }}
|}
 
{| class="wikitable" style="text-align:center;" width="80100%"
|+Examples of system variables
! width="30%" | Description !! width="40%" | TextWiki enteredsource !! width="30%" | ResultDisplayed text (for this help page)
|-
| rowspan="2" | Page names
| <nowikisyntaxhighlight lang="wikitext" inline>{{PAGENAME}}</nowikisyntaxhighlight>
| {{PAGENAME}}
|-
| <nowikisyntaxhighlight lang="wikitext" inline>{{FULLPAGENAME}}</nowikisyntaxhighlight>
| {{FULLPAGENAME}}
|-
| Name of the current namespace
| <nowikisyntaxhighlight lang="wikitext" inline>{{NAMESPACE}}</nowikisyntaxhighlight>
| {{NAMESPACE}}
|-
| Number of registered users
| <nowikisyntaxhighlight lang="wikitext" inline>{{NUMBEROFUSERS}}</nowikisyntaxhighlight>
| {{NUMBEROFUSERS}}
|-
| Number of pages in a given category
| <nowikisyntaxhighlight lang="wikitext" inline>{{PAGESINCATEGORY:"Weird Al" Yankovic albums}}</nowikisyntaxhighlight>
| {{PAGESINCATEGORY:"Weird Al" Yankovic albums}}
|-
| Current software version
| <nowikisyntaxhighlight lang="wikitext" inline>{{CURRENTVERSION}}</nowikisyntaxhighlight>
| {{CURRENTVERSION}}
|-
| Timestamp of last page revision
| <nowikisyntaxhighlight lang="wikitext" inline>{{REVISIONTIMESTAMP}}</nowikisyntaxhighlight>
| {{REVISIONTIMESTAMP}}
|}
 
The <syntaxhighlight lang="wikitext" inline>{{PAGENAME}}</syntaxhighlight> and NAMESPACE<syntaxhighlight lang="wikitext" inline>{{NAMESPACE}}</syntaxhighlight>variables are particularly useful, and frequently used, to change template behaviourbehavior based on the context. Forin example,which ifthey theare templateincluded. transcludesTemplates athat contain category linklinks (e.goften do this. cleanup templatesFor example, whicha cleanup template transcludecontains a category link categorizingto categorize the calling page as a pageone which needs cleanup), itso willthe oftentemplate checkis likely to condition that category link on the <syntaxhighlight lang="wikitext" inline>{{NAMESPACE}}</syntaxhighlight> variable to make sureso that talk pages, user pages, orand anywhereany elseother thepages tagthat might incidentallycall bethe placedtemplate incidentally do not themselves get categorized as pages needing cleanup.
 
===Nesting templates===
{{shortcut|WP:NEST}}
A template may call another template—this is called ''{{dfn|nesting}}'' and the called template is called, in this context, a ''{{dfn|subtemplate}}''. When WikiMedia expands the template, it expands subtemplates as the calls to them appear, so that the final product is essentially the result of expanding templates from the most deeply nested out.
 
Templates may contain other templates—this is usually called "nesting". As the template is processed, the wikitext produced by any nested templates is transcluded into the nesting template, so that the final product is essentially processed from the most deeply nested template out. While fairly straightforward in application, it involves some noteworthy quirks and tricks.
 
To pass a parameter value tofrom a nested template call to a subtemplate, placeuse a parameter tagreference asin the valuetemplate ofcall one ofto the nested template's parameterssubtemplate.
;Example{{colon}}
* Examples:
:Template:A contains <syntaxhighlight lang="wikitext" inline>"the quick brown {{B|{{{3}}} }} jumps over..."</syntaxhighlight>. Template:B (a subtemplate) contains <syntaxhighlight lang="moin" inline>'''{{{1}}}'''</syntaxhighlight>. Page X calls A with <syntaxhighlight lang="wikitext" inline>{{A|apple|pear|fox}}</syntaxhighlight> This expands to <syntaxhighlight lang="wikitext" inline>"the quick brown '''fox''' jumps over..."</syntaxhighlight>. The third unnamed parameter passed to Template:A gets passes as the first unnamed parameter to subtemplate B.
** Template:A contains <nowiki>"the quick brown {{B|{{{3}}}}} jumps over..."</nowiki> This takes the value passed to the third positional parameter of Template:A and passes it as the first positional parameter of Template:B, then returns the wikitext produced by B as part of the phrase.
 
** Template:A contains <nowiki>"the quick brown {{B|waldo={{{3}}}}} jumps over..."</nowiki> As previously, except the third positional parameter of Template:A is passed to the named parameter "waldo" of Template:B.
A template can even choose which subtemplate parameter to pass conditionally.
;Examples{{colon}}
:Template:A contains <syntaxhighlight lang="wikitext" inline>the quick brown {{B|{{{3}}}=fox}} jumps over...</syntaxhighlight>. Template:B (a subtemplate) contains <syntaxhighlight lang="moin" inline>'''{{{jumper}}}'''</syntaxhighlight>. Page X calls A with <syntaxhighlight lang="wikitext" inline>{{A|apple|pear|jumper}}</syntaxhighlight>. This expands to <syntaxhighlight lang="wikitext" inline>"the quick brown '''fox''' jumps over..."</syntaxhighlight>. The third unnamed parameter passed to Template:A is passed as the name of the parameter passed to subtemplate B with the value "fox".
 
Template parameters themselves can be chosen conditionally.
* Examples:
** Template:A contains <nowiki>"the quick brown {{B|{{{3}}}=fox}} jumps over..."</nowiki> Template:A passes the word "fox" as a named parameter of Template:B whose name is A's third positional parameter.
** <nowiki>{{#if: test string | value if test string is not empty | {{#if: test string | value if test string is not empty | value if test string is empty (or only white space) }} }}</nowiki>
{{shortcut|WP:TEMPLATE LOOP}}
Template recursion is not available; that is, a template may not call itself directly, or indirectly by calling other templates which call it. Attempts to do so will result in an error message describing a "template loop".
A template can call itself but will stop after one iteration to prevent an infinite loop.
 
When a nested templatesubtemplate contains unmatched braces—as in <syntaxhighlight lang="text" inline>{{tl|lb}}&#125;}</syntaxhighlight>—the unmatched braces are treated as text during processing, andprocessing—they do not affect the parsing of braces in the nestingcalling template. If theBut nestedwhere the template is substituted, however, the substitutionunmatched isbraces processedwill first,be andparsed this ''will'' change howas braces arewhen parsedthe inpage theis nestingsubsequently templatedisplayed. This has little practical use, but can occasionally introduce unexpected errors.
 
See the [[metamw:HelpManual:Advanced templates]] and [[metamw:HelpManual:Recursive conversion of wikitext]] for more information. These pages also contain information on unusual calls such as <nowiki>{{template {{{parameter|}}} }}</nowiki>.
 
===<span id="Noinclude, includeonly, and onlyinclude"></span>Inclusion control: noinclude, includeonly, and onlyinclude===
{{shortcut|WP:NOINCLUDE|WP:INCLUDEONLY|WP:ONLYINCLUDE}}
By default, when a templatepage iscalls transcludeda (or substituted)template, theMediaWiki entireincludes wikitextthe (code)expansion of the entire template page gets included in that of the targetcalling page. However, it is possible to modify that behaviourbehavior, using tags that specify which parts of the template code are to be included. This makes it possible tofor avoidthe transcludingtemplate to contain information intendedonly for display only onwhen the template page itself is displayed, such as the template's documentation, [[WPWikipedia:CategoryTemplate documentation|categoriesdocumentation]], andor [[WP:interwiki linksCAT#T|interwiki linkscategories]]. It is also possible to have parts of the codetemplate be transcludedincluded in calling pages, but ''{{em|not}} be displayed when the template page itself is displayed and not'' be processed onwhen the template page itself is saved (e.g., categories to be applied to the targetcalling pages which do not apply to the template). The tags are as follows:
* {{tagxtag|noinclude|p}}—the&nbsp;– The text between the noinclude tags willis {{em|not be}} included when the template is transcluded (substituted)called, but will be{{em|is}} processed onwhen the template's pageitself is displayed or saved; a common use is for template[[WP:Template documentation|documentation in templates]].
* {{tagxtag|onlyinclude|p}} &nbsp;specifies that nothingNothing on the page ''{{em|except''}} what appears between the onlyinclude tags willis included when the betemplate transcludedis (substituted)called.
* {{tagxtag|includeonly|p}}—the&nbsp;– The text between the includeonly tags will{{em|is}} beincluded transcludedwhen (substituted)the template is called, but willis {{em|not be}} processed onwhen the template's ownis displayed or pagesaved.
 
{| class="wikitable" style="text-align: center;"
! Wikitext
! What is rendered ''{{em|here''}} (sourcetemplate page)
! What is transcludedincluded ''{{em|there''}} (destinationcalling page)
|-
|<code><nowiki><{{tag|noinclude> |content=&nbsp;{{bxt|text1 </noinclude> }}&nbsp;}}&nbsp;{{mxtn|text2</nowiki></code>}}
|<code>{{bxt|text1}} {{mxtn|text2</code>}}
|<code>{{mxtn|text2</code>}}
|-
|<code><nowiki>&lt;{{tag|onlyinclude|content=&gtnbsp; {{bxt|text1 }}&ltnbsp;/onlyinclude}}&gtnbsp; {{mxtn|text2</nowiki></code>}}
|<code>{{bxt|text1}} {{mxtn|text2</code>}}
|<code>{{bxt|text1</code>}}
|-
|<code><nowiki><{{tag|includeonly> |content=&nbsp;{{bxt|text1 </includeonly> }}&nbsp;}}&nbsp;{{mxtn|text2</nowiki></code>}}
|<code>{{mxtn|text2</code>}}
|<code>{{bxt|text1}} {{mxtn|text2</code>}}
|-
|{{tag|onlyinclude|content={{tag|includeonly|content=&nbsp;{{bxt|text1}}&nbsp;}} }}&nbsp;{{mxtn|text2}}
|{{mxtn|text2}}
|{{bxt|text1}}
|}
 
Perhaps the most common issue with the use of these blocks is unwanted spaces or lines. It is important to remember that the effect of these tags begins immediately before the first angle bracket, not on the previous line or at the previous visible character; similarly the effect ends immediately after the last angle bracket, not on the next line or with the next visible character. For example:
 
:{{mxt|<nowiki>}}<includeonly></nowiki>}}
:;Examples
# :{{green!mxt|<nowiki>}}</nowiki><br /><nowiki></includeonly></nowiki>}}
#: {{maroon|<nowiki>}}</nowiki><br/><nowiki><includeonly></nowiki>}}
# {{green|<nowiki>}}<noinclude></nowiki>}}
#: {{maroon|<nowiki>}}</nowiki><br/><nowiki><noinclude></nowiki>}}
# {{green|<nowiki>{{template}}</includeonly><noinclude></nowiki>}}
#: {{maroon|<nowiki>{{template}}</includeonly></nowiki><br/><nowiki><noinclude></nowiki>}}
 
These tags can be nested inside each other, though (for a given page) this is really meaningful only applies tofor the {{tag|onlyinclude|o}} tag; nesting {{tag|includeonly|o}} and {{tag|noinclude|o}} tags is fairly pointless. Be careful not to splitproperly nest the tags, however. Constructions like {{tag|onlyinclude|o}}abc{{tag|includeonly|o}}def{{tag|onlyinclude|c}}ghi{{tag|includeonly|c}} will {{em|not}} work as expected. Use the "first opened, last closed" rule that is standard for HTML/XML.
 
===Problems and workarounds===
* The following techniques are helpful in debugging a template:
* If the first included character of a template or [[WP:PF|parser function]] is one of four wiki markup characters&nbsp;<code>:</code>&nbsp;<code>;</code>&nbsp;<code>*</code>&nbsp;<code>#</code><ref>These are defined in the [//doc.wikimedia.org/mediawiki-core/master/php/html/Parser_8php_source.html#l02360 <code>doBlockLevels</code> function of Parser.php]{{dead link}}</ref> then it is processed as though it were at the beginning of a line (even when the template tag is not). This allows the creation of various kinds of lists in templates where the template may not always be in the correct place for a list. To avoid this, either use {{tag|nowiki|s}} before the markup, see [[Help:Nowiki]], or use the [[HTML]] entities&nbsp;<code>&amp;#58;</code>&nbsp;<code>&amp;#59;</code>&nbsp;<code>&amp;#42;</code>&nbsp;<code>&amp;#35;</code> respectively. In some cases the HTML entities will work when the {{tag|nowiki|s}} does not.
** Use [[Special:ExpandTemplates]] to see the full recursive expansion of one or more templates.
* For issues involving the substitution of templates (for example, how to control whether subtemplates are substituted as well when the parent template is substituted), see [[Help:Substitution]].
** Use <code>subst:</code> to substitute a template (rather than transclude it), which can show more clearly what is happening when the template is transcluded; see [[Help:Substitution]].
* The template {{tl|Strip whitespace}} can be used to strip any initial or final whitespace from unnamed parameter values, if this would cause problems (named parameter values are automatically stripped in this way).
** Use <code>msgnw:</code> (short for "'''m'''e'''s'''sa'''g'''e, '''n'''o'''w'''iki") to more-or-less transclude the source of the template rather than its expansion. It is not perfect: lists are rendered, comments are removed, and single newlines are replaced with spaces (which is particularly confounding when transcluding wikitext tables).
* For debugging templates the following techniques are sometimes helpful:
* If the first character of a template expansion (or parser function result) is one of four wiki markup characters—<code>:</code>, <code>;</code>, <code>*</code>, <code>#</code>{{efn|These are defined in the [https://web.archive.org/web/20180625163321/https://doc.wikimedia.org/mediawiki-core/master/php/classParser.html#ad463888e40c078ac9bcfcaf1231e39d7 <code>doBlockLevels</code> function of Parser.php].}}, it is processed during display as though it were at the beginning of a line, even if the template call is not. This allows you to create various kinds of lists with templates where the template call may not be in the correct place for a list. To avoid this, use {{xtag|nowiki|s}} before the markup or {{tag|nowiki}} around it, or use the [[HTML]] entities <code>&amp;#58;</code>, <code>&amp;#59;</code>, <code>&amp;#42;</code>, <code>&amp;#35;</code>, or use the templates {{tl|colon}}, {{tl|;}}, {{tl|asterisk}}, {{tl|number sign}} (those templates may not exist at other wikis). In some cases, the HTML entities will work when the {{tag|nowiki|s}} does not. The problem often occurs when a parameter value in a template call starts with one of the four characters. See also {{tl|Encodefirst}}.
** Using "subst:"—substituting a template (rather than transcluding it) can show more clearly what is happening when the template is transcluded; see [[Help:Substitution]].
* For issues with template substitution, such as how to control whether subtemplates are substituted as well when the parent template is substituted, see [[Help:Substitution]].
** Using "msgnw:"—this keyword (short for "message, nowiki") transcludes the wikitext of the template page, more or less, rather than the processed contents. It is not perfect: lists are rendered, comments are removed, and single newlines are replaced with spaces (which is particularly confounding when transcluding wikitext tables).
* You can use the template {{tlx|Trim}} to strip any initial or final whitespace from unnamed parameter values if this would cause problems; <em>named</em> parameter values are automatically stripped in this way.
** Using [[Special:ExpandTemplates]] to see the full recursive expansion of one or more templates.
* To protect server resources and avoid infinite loops, the parser imposes certain limits on the depth of transclusion nesting of transclusions and on the page size with expanded templates. This may cause pagesa page to break whenif it usinguses very complex templates, particularly if there are multiple such templates on the same page. For more information, see [[WP:Template limits]]. AYou can check a page's overall load on the server can be checked by examining the generated HTML for a page and looking for the "<code>NewPP limit report"</code> comments.
* Do not use <code>=</code> wikimarkup to create a section headersheader withinin a template which is intended for use in article space—thisspace; this will create an <code>[edit]</code> link on a page that whentranscludes transcludedthe template that will confusingly open the <em>template</em> for editing.
** You may avoid <code>[section edit]</code> links to the template by including <code><nowiki><includeonly>__NOEDITSECTION__</includeonly></nowiki></code>.
 
===Documentation===
{{Details|WikipediaWP:Template documentation}}
Documentation for users, together with the template's categories, normally goes after the template code, inside {{tag|noinclude}} tags. It is normally necessary to put the opening {{tag|noinclude|o}} tag immediately after the end of the code, with no intervening spaces or newlines, to avoid transcluding unwanted whitespace.
Categorizing your template and documenting its proper usage will make it easier for other editors to find and use.
 
In the case of complex templates, the documentation is often kept on a separate [[WP:Subpages|subpage]] of the template page (named "Template:{{var|XXX}}/doc"). This applies especially to many [[WP:Protection policy|protected]] templates, so that non-administrators can edit the documentation. To do this, place a call to the {{tlx|Documentation}} template after the main template code and within {{tag|noinclude}} tags. If the "/doc" subpage does not exist, a link appears when you display the template that you can use to create the subpage.
Documentation for users, together with the template's categories, is normally placed after the template code, inside {{tag|noinclude}} tags. It is normally necessary to put the opening {{tag|noinclude|o}} tag immediately after the end of the code, with no intervening spaces or newlines, to avoid transcluding unwanted whitespace.
 
The documentation subpage, rather than the template itself, is normally what is placed in categories to represent a template.
In the case of complex templates, the documentation (together with categories) is often kept on a separate [[WP:subpage|subpage]] of the template page (named "Template:XXX/doc"). This also applies to many [[WP:protection|protected]] templates (to allow the information to be edited by non-administrators). This is achieved by placing the {{tl|Documentation}} template after the main template code (within {{tag|noinclude}} tags). If the "/doc" subpage does not exist, a link will then appear enabling it to be created.
 
===Categorization===
{{See also|Wikipedia:Categorization#Templates}}
====Categorize pages by template inclusion====
Some templates containgenerate category definitionsdeclarations in their transcluded codeexpansion, i.e.since theythe aretemplate is intended to place the targetcalling pages in particular categories. This is often done with maintenance categories. (placingPlacing articles into ordinary content categories in this way is discouraged). When doing this, ityou may be necessaryhave to use {{tag|includeonly}} tags to keep the template itself out of the category. While developing, testing, sandboxing, or demonstrating a template intended to apply a category, either temporarily replace each category with a test category (starting with [[:Category:X1|X1]], [[:Category:X2|X2]], or [[:Category:X3|X3]]) or suppress categorization (see [[WP:CATSUP|category suppression in templates]]).
 
====Categorize templates====
Categorizing your template and documenting its proper usage will make it easier for other editors to find and use.
Categorization declaration <code><nowiki>[[Category: Some-topic templates ]]</nowiki></code> should be placed on the template's documentation page (or inside {{tag|noinclude}} tags, if there is no documentation page) to avoid polluting the transcluding pages.
 
Category declarations for a template itself should be placed on the template's documentation subpage (or inside {{tag|noinclude}} [[html tag|tags]] if there is no documentation subpage) to avoid placing calling pages in the category.
 
===Aliases===
 
Aliases can be created withA [[WP:redirectRedirect|redirectsredirect]] of a template functions as an alias. For example, [[Template:Tsh]] redirects to [[Template:Template shortcut]]., Thenso you can writecode {{tlptlx|tsh|{{var|foo}}}} instead of {{tlptlx|Template shortcut|{{var|foo}}}}.
 
It's is good to prepare template aliases whichfor only differvariations in whitespaceswhitespace and capitalization. For example, there's is a template called {{tltlx|See Wiktionary}}. The "W" is capitalcapitalized, since the word "Wiktionary" is so., Butbut a redirect {{tltlx|See wiktionary}} (with lowerlowercase "w") exists because userseditors aremay likelymisremember toit useas the latter.
 
==Template limits==
{{details|Help:Template limits}}
 
{{shortcut|WP:INCLUDELIMIT}}
{{Anchor|Expand limits}}
'''"Post-expand include size" limit.''' When templates are rendered or expanded to HTML for viewing in your browser, they use memory. This is called the "post-expand include size" and has a limit of 2,048,000&nbsp;bytes. This size is included as an invisible comment in the HTML output—use your browser's view source feature to show the raw HTML and search for "newpp". The report will look like:
{{details|Wikipedia:Template limits}}
<syntaxhighlight lang="html">
'''"Post-expand include size" limit.''' When templates are rendered or expanded to HTML for viewing in your browser, they use memory. This is called the "post-expand include size" and has a limit of 2,048,000 bytes. This size is included as an invisible comment in the HTML output—use your browser's view source feature to show the raw HTML and search for ''newpp''. The report will look like:
<source lang="html4strict">
<!--
NewPP limit report
Line 341 ⟶ 393:
Expensive parser function count: 2/500
-->
</syntaxhighlight>
</source>
 
The example shows that template expansion is using 63k63,476&nbsp;bytes out of 2M2,048,000&nbsp;bytes of available memory.
 
'''Display problem.''' If too many templates are included on a page, the post-expand include size may exceed the limit. When this happens, templates after the limit will no longer expand and will instead display as a wikilink (for example, {{red|1=<u>Template:''templatename''{{var|Template name}}</u>}}). Common causes are the inclusion of too many [[Help:Citation Style 1|citation templates]], [[WP:NAVBOX|navbox templates]], and/or [[Wikipedia:WikiProject Flag Template|flag templates]]. To resolve this problem [[WikipediaWP:Substitution|substitute]] templates, directly [[Help:Template limits#invoke syntax|invoke]] modules, remove templates, or [[WP:Splitting|split]] the page.
 
'''Non-rendered tranclusions still count towards limit.''' For example, a page which contains only <code><nowiki>{{#if:{{:Main Page}}}}</nowiki></code> would still have a post-expand include size even though it would have no output at all.
 
'''Non-renderedThe tranclusionssame stillapplies countto towards[[WP:Lua|Scribunto limitmodules]].''' For example, a page which contains only <code><nowiki>{{#ifinvoke:{{:Main Page}}Test|main}}</nowiki></code> would still have aincrease post-expand include size even thoughif itModule:Test wouldwere have no output at all.simply:
<syntaxhighlight lang="lua">
mw.getCurrentFrame():preprocess "{{msgnw::Main Page}}" -- remove this line and post-expand include size becomes zero
return {main = function() end} -- p.main() has no return value
 
</syntaxhighlight>
The same applies to [[Wikipedia:Lua|Scribunto modules]]. For example, <code><nowiki>{{#invoke:Test|main}}</nowiki><code> would still increase post-expand include size even if Module:Test were simply: <syntaxhighlight lang=lua>mw.getCurrentFrame():preprocess'{{msgnw::Main Page}}'--remove this line and post-expand include size becomes zero
return {main = function()end}--main has no return value</syntaxhighlight>
 
==Lua programming language==
{{main article|WikipediaWP:Lua}}
Since February 2013The [[Lua (programming language)|Lua programming language]] is available for use viathrough the [[mw:Extension:Scribunto|Scribunto]] MediaWiki extension. Lua codeYou can beembed embeddedLua code into wiki templates by employing the "<code><nowiki>{{#invoke:}}</nowiki>"</code> functionality of the Scribunto MediaWiki extension. The Lua [[source code]] is stored in pages called modules, and templates invoke these individual modules are then invoked on template pages. For example, you can invoke [[Module:BananasExample]] can be invoked usingwith the code <code><nowiki>{{#invoke:BananasExample|hello}}</nowiki></code> to print the text "Hello, world!{{#invoke:Example|hello}}".
 
==Terminology==
A ''template'' is a Wikipedia page whose purpose is to be transcluded or substituted in another page. Templates are usually in the [[WP:Template namespace|template namespace]], but don't have to be. Pages can transclude or substitute any page, not just templates; what makes a page a template is the page's purpose.
 
''Calling'' a template means transcluding or substituting one. A page calls a template. The wikitext on a page that causes the page to call a template is called a ''template call''. For example, <syntaxhighlight lang="wikitext" inline>{{sic|constellation prize}}</syntaxhighlight>. Template calls are always delimited by double braces (<syntaxhighlight lang="text" inline>{{}}</syntaxhighlight>), but not everything enclosed in double braces is a template call.
 
''Expansion'' is the process of generating page source from a template, when a page calls it, by applying parameters and other features. MediaWiki expands a template as it renders a page. One can also say that the template itself expands, so both "MediaWiki expands {{param|1}} as the value of the first positional parameter" and "{{param|1}} expands as the value of the first positional parameter" work.
 
''Expansion'' of a page is also the page source that results from template expansion. For example, the expansion of the {{tl|sic}} template when called by <syntaxhighlight lang="wikitext" inline>{{sic|constellation prize}}</syntaxhighlight> is <syntaxhighlight lang="wikitext" inline>constellation prize&#32;&#91;''[[sic]]''&#93;</syntaxhighlight>.
 
The displayed page content generated by a template call (which is the rendering of the expansion of the called template) is the ''template result''. The template result generated by the template call <syntaxhighlight lang="wikitext" inline>{{sic|constellation prize}}</syntaxhighlight> is "{{sic|constellation prize}}".
 
The ''name'' of a template is the name of the Wikipedia page (which is also the title of the page). The namespace is normally left off if it is "Template" (which it almost always is). Furthermore, it is customary to write the name with double braces, like a template call, to emphasize that it names a template. For example, "Use the {{tl|tm}} template to generate the trademark symbol." But don't go so far as to put a template name in the code font, to prevent confusion with an actual template call. {{tlf|tm}} is a template name, but {{tnull|tm}} is a template call.
 
Some template calls perform a tagging function; such a template call is often called a ''tag'', as in, "If you are in the middle of a major edit, place an {{tl|in use}} tag at the top of the page." This is one of many ways the term "tag" is used in Wikipedia.
 
A ''parameter'' is a particular piece of information that can be specified in a template call to affect the expansion of the template. A parameter has a ''value''. A named parameter has a ''name''; an unnamed parameter has a ''position''. A template call ''specifies'' a parameter and the code that does that is a ''parameter specification''. A template ''defines'' a parameter (not explicitly -- just by the template being designed to use it). The code in a template that expands to the parameter value (e.g. {{param|myparam}}) is a ''parameter reference''.
 
===Common variations===
It is common to use "template" to refer not only to a template, but to a template call, a template result, and a template name.
 
For example:
* I am going to put more detail in the {{tl|short description}} template on this page.
* Upon seeing an {{tl|under construction}} template, the reader may decide to come back later.
* There are many kinds of infoboxes. The templates all start with "Infobox".
 
These usages can be confusing, especially to someone less familiar with templates. Consider using more specific language.
 
==Template search==
{{main|WikipediaWP:Template messagesindex}}
As an alternative to using this index linked above, you can search the Template namespace using the [[Special:Search]] box below:
 
<div class="inputbox-hidecheckboxes">
<inputbox>
type=fulltext
Line 367 ⟶ 449:
searchbuttonlabel=Search Template namespace
break=no
placeholder=i.e.g. Citation
</inputbox>
</div>
 
==See also==
=== Help pages ===
 
{{div col|colwidth=20em}}
{| class="wikitable"
!width=25%|Help pages
!width=25%|Manual pages
!width=25%|Special pages
!width=25%|Other pages not for direct viewing
|- style="vertical-align:top;"
|
*[[Wikipedia:Advanced template coding]]
* [[m:Help:Template]]
* [[meta:User:Happy-melon/Templates]]
* [[m:Help:Advanced templates]]<!-- m: not directly portable due to examples -->
* Introductions:
** [[Transclusion]]
** [[Help:A quick guide to templates]]
** [[mw:Help:TemplatesSubstitution]]<!-- maybe portable, test it -->
** [[Help:CalculationTransclusion]]
* [[Wikipedia:Template messages]]
* [[Help:Magic words]]
* [[mw:Help:MagicManipulating wordsstrings]]
* [[Help:Metatemplating]]
* [[WP:Advanced template coding]]
* [[WP:Template documentation]]
* [[WP:Template index]]
* [[WP:Template limits]]
* [[WP:Template namespace]]
* [[WP:Template sandbox and test cases]]
* [[WP:TemplateData]]—standardized template description used by [[Wikipedia:VisualEditor|VisualEditor]]
* [[WP:WikiProject Templates]]
* [[mw:Manual:Advanced templates]]
* [[mw:Manual:Expr parser function syntax]]
* [[m:User:Happy-melon/Templates]]
* [[mw:Help:ExpandTemplates]]
* [[mw:Help:Extension:ParserFunctions]]
* [[mmw:Help:ParameterMagic defaultwords]]<!-- m: -->
* [[mw:Help:Templates]]
* [[Help:Substitution]]<!-- maybe portable, test it -->
{{div col end}}
* [[Wikipedia:Template documentation]]
 
* [[Wikipedia:Template namespace]]
=== Mediawiki manual pages ===
* [[Wikipedia:Template limits]]
* [[mw:Manual:$wgEnableScaryTranscluding]]
* [[Wikipedia:Template test cases]]
* [[mw:Manual:$wgNonincludableNamespaces]]
* [[Wikipedia:WikiProject Templates]]
|
* [[mw:Manual:$wgEnableScaryTranscluding|Interwiki transclusion]]
* [[mw:Extension:ExpandTemplates]]
* [[mw:Manual:Parser.php]]
* [[mw:Manual:Parser functions]]
|
 
* [[Wikipedia:Database reports/Templates transcluded on the most pages]]—shows the number of pages in which each template is transcluded, not counting transclusions through redirects
=== Special pages ===
* [[Special:Unusedtemplates]]—templates which are not transcluded (however, they may be used for substitution)
* [[WP:Database reports/Templates transcluded on the most pages]]—not counting transclusions through redirects
* [{{fullurl:Special:Allpages|namespace=10}} Special:Allpages (namespace 10)] all templates on this server
* [{{fullurl:Special:Allpages|namespace=10}} Special:Allpages (namespace 10)]—all pages in the Template namespace
* [[Special:ExpandTemplates]]
* [[Special:Unusedtemplates]]—templates which are not transcluded (but may be used for substitution)
|
 
* Multilingual portal pages, see [[meta:www]]
=== Other backend pages ===
* CSS and JS pages, see [[Help:User style]]
* [[Help:User style]]—CSS and JS pages
* Pages in the MediaWiki namespace, see [[Help:System message]]
* [[Help:System message]]—MediaWiki namespace pages
* [[Wikipedia:Book sources]], used by [[Special:Booksources]]
* [[m:Project portals]]—Multilingual portal pages
* [[WP:Book sources]]—used by [[Special:Booksources]]
* [[m:Spam blacklist]]
* [[Template:Example]]
|}
 
==Notes==
{{reflistNotelist}}
 
{{Wikipedia template messages}}
{{Wikipedia help pages}}
{{Wikipedia technical help}}
 
{{Wikipedia template messages|state=collapsed}}
{{Wikipedia technical help|collapsed}}
[[Category:Template documentation| ]]
[[Category:Wikipedia how-to]]
[[Category:Wikipedia template help]]