Help:Template

From Wikipedia, the free encyclopedia

This is a copy of the master help page at Meta. Do not edit this copy.
Edits will be lost in the next update from the master page. See below for more information.
Editing
Start new pages
Page name

Referencing
Links
Piped links
Interwiki linking
Footnotes (References)

Formatting
Wikitext
Lists & Tables
Image & file uploads
Formulae

Organising
Sections
Categories
Redirects (forward)
Namespaces
Moving a page
Page size

Fixing mistakes
Reverting edits
Show preview

Saving effort
Editing shortcuts
Edit toolbar
Magic words
Templates
Variables
Calculation

Communicating
Edit summary
Talk page
Edit conflict
Minor edit

Other
Characters
Sandbox


Shortcut:
WM:TEMP
View this page using:
[http://en.wikipedia.org../../../../articles/t/e/m/Help%7ETemplate_43b9.html
new preprocessor
diff

The (whole) contents of one page can be placed onto another page via a process called transclusionhttp://en.wikipedia.org/wiki/Wikipedia:Transclusion (comparable to calling a subroutinehttp://en.wikipedia.org../../../../articles/s/u/b/Subroutine.html facility). If a page is specially intended for this purpose it is called a template.

Expansion is at page view time [1] unless substitution is applied, in which case the expanded wikitext is saved. The wikitext for the parameter name is expanded, further see the parameter section.

This page and its extension Help:Advanced templates provide a reference manual on templates in MediaWiki. See also m:User:Happy-melon/Templateshttp://meta.wikimedia.org../../../../articles/h/a/p/User%7EHappy-melon_Templates_1ae7.html. For an introduction, see A quick guide to templates and mw:Help:Templates. For syntax often used within templates, see Help:Parser function, Help:ParserFunctions and other "Advanced functioning" help pages listed below.

Note: The master version of this page is the page m:Help:Template on Meta-Wiki; template demos work there, but may not work if you are viewing a copy of this page on another project.

Contents

General

The template namespace is the namespace with prefix "Template:" (this prefix can be used in all languages, but the canonical prefixes in languages other than English include Vorlage, Modèle, Sjabloon, with colon; the site WikiFAQ calls it Snippet).

A page in this namespace is called a template. The contents of such a page (either fixed or depending on parameters and/or variables) is designed to be useful for insertion in other pages (transclusion, creating a compound document). In a what links here list, the message with id 'Istemplate' (talk) is used, by default "inclusion", sometimes "transclusion", currently on this wiki "transclusion".

The syntax for insertion of the page "Template:name" is {{name}}. This is called a template tag, and comprises two instances of the "brace" at either side of the template page name, excluding the "Template:" prefix.

Example:

"{{tc}}" gives "in" [1]

This reference in the wikitext causes insertion of the template content when the referring page is rendered. Various equivalent terms are:

  • inclusion / including the page - "inclusion" by itself may be ambiguous, since one can say that a section etc. is included in a page even if there is no transclusion; based on these terms are the tag names "noinclude" and "includeonly", see below
  • transclusion / transcluding the page - this is more specific than "inclusion"
  • page embedding / embedding the page

Terms too general to be used with "page", therefore only used with "template":

  • template call / calling the template - referring more to the template tag than to the result
  • template use / using the template

Depending on context "including" can be used as opposed to substituting the template.

Pages in namespaces other than the "Template" namespace can also be used as templates, except for pages in namespaces specified in $wgNonincludableNamespaces. To use a page in the main namespace as a template, add a colon before the page name.

Also it provides an alternative way of calling a template, which can be used in the case of a name conflict with a variable, e.g. Template:Ns:3 and Template:PAGENAME; while {{Ns:3}} and {{PAGENAME}} give User_talk and Template, {{:Template:Ns:3}} and {{:Template:PAGENAME}} give Template:Ns:3 and Template:PAGENAME.

Using a page outside the template namespace as template can be useful for:

  • quoting interface messages in the MediaWiki namespace
  • templates for personal use in subpages of one's userpage, e.g. for experimenting
  • inclusion of pages in other pages in the same namespace, e.g. having an extra page associated with each page, such as a to-do list, with a simple name correspondence; it can be created and included with {{{{NAMESPACE}}:{{PAGENAME}}/todo}}

If the page to be transcluded does not exist, then a link to the edit page is produced (for conversion details see m:Template:Existshttp://meta.wikimedia.org../../../../articles/e/x/i/Template%7EExists_0140.html). Thus, one way of making a template is putting the tag first, and then following the link. An exception is that transclusion of a "non-existing" page in the MediaWiki namespace trancludes the default content of that page. In other words, apart from transcluding a page one can also transclude a system message in a specified language (by default the site language); the result is independent of the user-specified interface language.

One can call a template that calls another template. If a template calls itself directly or indirectly, inclusion works only on one level for each template. The second-level inclusion is replaced by a link (possibly a self-link), with HTML comment:

<!-- WARNING: template loop detected -->

However, with templates redirecting to the template that one would want to call recursively, one can achieve recursion without having to make copies of the whole template content, with the number of levels limited by the number of redirects. See also Repetition within a page and m:Template:List of template calls (backlinks, edit).

A variable in a template which depends on the page, e.g. {{PAGENAME}}, is expanded based on the referring page, not on the template.

A list of pages embedded in a page (as recorded in the templatelinks table), all with links, is given on the edit page. Notes:

  • on a section edit page first the whole list is given, i.e. also the templates used in other sections; after pressing preview only those in the section, updated for the edits made, if any; preview on first edit gives the full list;
  • similarly, when editing an old version of a page, the list is first given for the current version, while after pressing preview the templates that used to be included are shown, updated for the edits on the old version made in the current session, if any;
  • if the name of an embedded page is an expression, e.g. {{abc{{CURRENTDAY}}}}, currently giving Template:Abc10, or {{{{#ifexist:Template:A|A|1x}}|Template does not exist}}, currently giving A-class article, the current template name is shown.

(Supported in version 1.4 and higher.)

In a template name the character "#" and any characters after that are ignored: "{{tc#abc}}" gives "in". This is used in en:template:hif ( talk edit history links ).

A wikitext with consecutive double opening braces and consecutive double closing braces is interpreted as containing a template parameter tag with triple braces. To avoid that, use a space in at least one of the two quadruples. For example, "{{{{tc}}}}" gives "{{{{tc}}}}", while "{{ {{tc}}}}" gives "\in".

With Special:ExpandTemplates one can view the expanded wikitext a template call produces, as intermediate step toward rendering. The same is also produced with a URL like http://en.wikipedia.org../../../../raw/Help%7ETemplate_43b9.

Talk pages

Even if a template is intended for use on talk pages, the template page should not be put in a talk namespace, because there would be no page for discussing it. If it is for general use it is often put as usual in the template namespace, see e.g. Wikipedia:Talk page templateshttp://en.wikipedia.org/wiki/Wikipedia:Talk page templates and Wikipedia:Template messages/User talk namespacehttp://en.wikipedia.org/wiki/Wikipedia:Template messages/User talk namespace. An auxiliary template for personal use for a user talk page can best be put in a subpage of the user page, not one of the user talk page, for example "User:Abc/Talk intro" rather than "User talk:Abc/Intro"; this allows discussion of the template at "User talk:Abc/Talk intro".

Case sensitivity

As usual the template name is case sensitive except (on most projects) for the first letter, and a blank space is equivalent with an underscore (as opposed to parameter names, see below: they are case-sensitive, even with respect to the first letter, and spaces are distinguished from underscores).

Use of templates across projects

A template only works when referred to from a page in the same project. To use it in another project, one has to copy it to there. Bugzilla:1126 is a request to lift that restriction, i.e. allow interwiki use of templates.

The adjustments needed in the copy, to work on the other project, can be reduced by using {{SERVER}}, localurl, and generic namespace names, and writing links in a way that works on multiple projects, e.g. m:Help:Table. For copying multiple templates, export and import can be helpful. It is also convenient if the template names can be the same on the other project. Therefore, when choosing template names, check which names are in use on other projects to which people might want to copy the templates. Note that if a template is referred to by something like abc{{NAMESPACE}}, a project with different namespace names requires a different template name, or a redirect.

Transclusion across projects, hence changing contents from a central place, is only possible:

  • for content in the form of an image on Commons, to any page,
  • for editable content on an image page on Commons, including content transcluded from other pages on Commons, to the corresponding local image pages, if there is no local image with the same name

Templates on the central Wikia work in the separate Wikia projects, provided that the prefix "wikia:" is used, see shared templates on Wikia. [2]

Sometimes multiple projects require pages which are partly the same and partly different. For example, on some projects "m:" is used as interwiki link to Meta, and on some projects "MetaWikipedia:". In this case a common wikitext can be used, calling project-specific templates. In the example the wikitext of the page could contain {{meta}}, and we would have on each wiki a Template:Meta containing the required prefix.

Parameters

Template parameters are called-by-valuehttp://en.wikipedia.org../../../../articles/p/a/r/Parameter_%28computer_science%29.html#Calling_conventions, and therefore input parameters only (see also the section "Template expansion" below).

In the template call, while the number of parameter definitions (here two) can vary, the syntax is either

  • {{templatename|parname1=parvalue1|parname2=parvalue2}} with tags {{{parname1|default}}}, {{{parname2|default}}}, etc. in the template, or
  • {{templatename|parvalue1|parvalue2}} with tags {{{1|default}}}, {{{2|default}}}, etc. in the template, or
  • a mix of the two.

Thus a template call has, after the template name, zero or more parameter definitions, separated by raw pipes (raw means here: in the wikitext, not just in the expanded wikitext, and not inside double or triple braces or double brackets). Furthermore, each parameter definition containing a raw equals sign is split around the first such equals sign into a parameter name and parameter value. In this stage the wikitexts for the parameter names are expanded, but not yet those for the parameter values.

For any remaining parameter definitions the implicit numbers of the parameters are 1, 2, 3, etc. (so if there are also named parameters the implicitly numbered parameters are numbered according to the position among themselves, not the position in the mixed list as a whole). If a parameter would be assigned a value more than once (more than once as named parameter, or once as implicitly numbered one and once or more as named one), working from left to right through the mixed list only the last assignment is retained. The result is an associative array of parameter names and corresponding wikitexts for the parameter values.

A formal parameter (the placeholderhttp://en.wikipedia.org../../../../articles/f/r/e/Free_variables_and_bound_variables.html for the parameter value) is represented by a parameter tag with three pairs of braces, optionally with a pipe and a default. The parameter names in assignments matching a formal parameter are selected. Only the wikitexts for the parameter values of these are expanded, as well as the defaults of the undefined ones, if specified. The template call is replaced by the template content, where the parameter tags with matching names are replaced by their values or defaults. The result of this step can be viewed by applying subst.

While what was explained involved expansion of wikitext for the template name, all parameter names and selected parameters can involve recursion in expanding the template.

To illustrate the above, a page with {{t1demo|{{ta}}|{{tb}}|{{tc}}={{td}}|1={{te}}|2={{tf}}}}, with m:Template:t1demo (backlinks, edit) only using parameter {{{1}}}, and giving startTelugu: {{{1}}}end, transcludes templates tc and te only.

A parameter tag such as {{{3|stu}}} can both be referenced explicitly with e.g. 3=pqr, or implicitly by putting pqr in the third position among the unnamed parameter definitions. If the name is not a "small" positive integer it can only be referenced explicitly.

Comparison between named and implicitly numbered parameters:

  • To specify the value of a particular implicitly numbered parameter all previous ones have to be defined too (often the empty string is used as value if the assignment is only for this reason).
  • With implicit numbering the call is shorter (except if many extra parameters have to be defined because of what was just mentioned).
  • Named parameters can be specified in any order.
  • An implicitly numbered parameter can be assigned a value containing "=" only indirectly (see below).
  • Spaces and newlines are stripped from the start and end of parameter values of named parameters, but not of implicitly numbered parameters. Therefore the best name for a separator parameter (specifying how items of output are separated) is "1". This has e.g. been done in m:Template:for (backlinks, edit). See also Help:Newlines and spaces; also, compare conditional whitespace.

The default (optional, together with the pipe character in front) can be different for every occurrence, and applies if no value is specified when calling the template, not to be confused with the case that the empty value is specified.

To distinguish between a parameter being defined and non-empty on one hand, or undefined or empty on the other hand, use #if: with a blank default:

{{ #if: {{{param|}}} | param is defined and non-empty | param is undefined or empty}}.

To distinguish between defined (and possibly empty) and undefined, use:

{{ #ifeq: {{{param|+}}} | {{{param|-}}} | param is defined | param is undefined }}.

In the case of page substitution with an undefined parameter, not the default but the parameter itself with default is substituted into the wikitext. If this is not desired, see Help:Substitution#Parameter_default_considerations for an alternative (it also uses the #ifeq just mentioned).

Example: named parameter substitution

Let's create a template called Name-example (that is, the template will be Template:Name-example), with a parameter for the first name which we will call firstName, and a parameter for the last name which we will call lastName.


Type the following in the new Template:Name-example:

:I am a template example, my first name is '''{{{firstName}}}''' and my last name is '''{{{lastName}}}'''.
:
:You can reference my page at [[{{{lastName}}}, {{{firstName}}}]].

On a second page, type this: {{Name-example}}

The result is: I am a template example, my first name is {{{firstName}}} and my last name is {{{lastName}}}.

You can reference my page at [[{{{lastName}}}, {{{firstName}}}]].

Because the template has no parameters.

But if we type this on the second page: {{Name-example | firstName=John | lastName=Smith}}

The result will looks like this:
I am a template example, my first name is John and my last name is Smith.

You can reference my page at Smith, John.

To analyse the working, one can apply Special:ExpandTemplates to see the expanded wikitext as intermediate result:

:I am a template example, my first name is '''John''' and my last name is '''Smith'''.
:
:You can reference my page at [[Smith, John]].

When this wikitext is applied directly the resulting rendering is the same.

Example: numeric parameter substitution

An example of how the contents of a parameter function.

Let us first define a template with the name t1demo, which will

  • expect a single argument
  • give back the text of that argument, with no spaces before or after it, between "start-" and "-end":
start-{{{1}}}-end

the definition of course being on page Template:t1demo.

  1. Calling the template named t1demo with a parameter value of "a", i.e.,
    {{t1demo|a}}
    gives
    "startaend"
  2. Calling the template named t1demo with a parameter value of " " (a blank space), i.e.,
    {{t1demo| }}
    gives
    "start end" .
  3. Calling the template named t1demo with a parameter value of "" (an empty string), i.e.,
    {{t1demo|}}
    gives
    "startend".
  4. Calling the template named t1demo and not passing any parameters, i.e.,
    {{t1demo}}
    gives
    "start{{{1}}}end".

If something like {{{1}}} or in fact any {{{name}}} is visible on an ordinary page it typically indicates that a mandatory parameter of a template used on this page isn't defined.

Declaring a default value

Main article: Help:Parameter default.

Let us define a template with the name t which contains a single numbered parameter 1 with a default of pqr. The only difference between the effects of t and t1demo appears when they are called with no parameter (and no "|"):

start-{{{1|pqr}}}-end

the definition of course being on page Template:t.

  1. Calling the template named t with a parameter value of "a", i.e.,
    {{t|a}}
    gives
    "start-a-end

</body></html>".

  1. Calling the template named t with a parameter value of " ", i.e.,
    {{t| }}
    gives
    "start- -end

</body></html>".

  1. Calling the template named t with a parameter value of "", i.e.,
    {{t|}}
    gives
    "start--end

</body></html>".

  1. Calling the template named t with named parameter 1=, i.e.,
    {{t|1=no surprise}}
    gives
    "start-no surprise-end

</body></html>".

  1. Calling the template named t with 1= after an unnamed parameter, i.e.,
    {{t|no|1=surprise}}
    gives
    "start-surprise-end

</body></html>".

  1. Calling the template named t with 1= before an unnamed parameter, i.e.,
    {{t|1=no|surprise}}
    gives
    "start-surprise-end

</body></html>".

  1. Calling the template named t and no parameter at all, i.e.,
    {{t}}
    gives
    "start-pqr-end

</body></html>".

  1. Calling the template named t and no named or unnamed parameter 1, i.e.,
    {{t|2=two}}
    gives
    "start-pqr-end

</body></html>".

Restrictions on parameter values

An implicitly named parameter can be assigned a value containing an equals sign, but only indirectly. Methods (here with example using Template:t1demo (talk, links, edit)) include:

  • Write it as the default of an undefined parameter, as in {{{| a=b }}}: start a=b end.
  • Use template:= ( talk edit history links ), e.g. " a{{=}}b ": start a=b end.
  • If it is just for display, the equals sign can be replaced by the HTML entity &#x3d;: start a=b end.

The same example with "1= a=b " gives starta=bend.

With the old preprocessor the "=" in "class=error" disturbs the numbering of unnamed parameters, if one of them produces an error message: {{t1demo|{{#expr:1/0}}}} gives startExpression error: Division by zeroend.

Reasons for using an unnamed parameter include:

  • Spaces and newlines are stripped from the start and end of parameter values of named parameters (as demonstrated).
  • Not disturbing the numbering of following unnamed parameters (alternatively, the parameter definition can be prefixed with an extra "|", providing a dummy definition of an unnamed parameter, which is overwritten by the parameter definition concerned).

Any unmatched pairs of two consecutive braces or brackets must be placed in nowiki tags. Braces can be used for nested template parameters, nested templates or parser functions while brackets can be used for links. Unmatched pairs not placed in nowiki tags either prevent template expansion or are taken as closing braces for the template call.

For example, using Template:t1demo containing "start{{{1}}}end<noinclude>

[[Category:Demo template]]</noinclude>":

  • {{t1demo|abc]]def[[ghi}} gives {{t1demo|abc]]def[[ghi}} (the template is not expanded; see also [2] where this example causes several sections not to be displayed).
  • {{t1demo|abc}}def}} gives startabcenddef}} (the first closing braces are taken as those for the template call).

Without restriction:

  • {{t1demo|abc]def[ghi}} gives startabc]def[ghiend.
  • [http://1 {{t1demo|abc]def}} gives startabcdefend.

A parameter value can be quite long, see Help:Long parameter demo.

A parameter value containing a pipe character

To define a parameter value containing a pipe character (|) which is not part of a template call, parser function call, piped link or image tag, use Template:! containing "|". Using Template:t1demo containing "start{{{1}}}end<noinclude>

[[Category:Demo template]]</noinclude>", compare {{t1demo|a{{!}}b}} giving starta|bend, {{t1demo|a&#124;b}} giving starta|bend and {{t1demo|a|b}} giving startaend. The difference between the first and the second is that in the first case the expanded wikitext is start-a|b-end, while in the second case it is start-a&#124;b-end. This is rendered the same in final output but makes a difference when used in table syntax: this requires the "real" pipe character.

Using Template:2x containing "{{{1}}}{{{1}}}",

{{2x|{{{!}} 
{{!}} A 
{{!}} B
{{!}}- 
{{!}} C
{{!}} D
{{!}}}
}}

gives

A B
C D
A B
C D


while

{{2x|{&#124; 
&#124; A 
&#124; B
&#124;- 
&#124; C
&#124; D
&#124;}

}}

gives

{| | A | B |- | C | D |} {| | A | B |- | C | D |}


and

{{2x|{| 
| A 
| B
|- 
| C
| D
|}
}}

gives

{{

Similar constructs can allow a parameter value to contain a double closing brace. Even a parameter name can contain "|" and "}}" in this way, but that seems of little use. However, a pagename cannot contain "|" or a brace.

Mix of named and unnamed parameters

In the case of a mix of named and unnamed parameters in a template tag, the unnamed parameters are numbered 1,2,3,.., so they are not numbered according to the position in the mixed list as a whole. For example, {{t sup|foo=1|2|bar=3|4|5|6|7}} using Template:t sup containing "{{{1}}}-{{{2}}}-{{{3}}}<noinclude>[[category:Demo template]]</noinclude>" gives 2-4-5.

However, {{t sup|3=1|2|1=3|4|5|6|7}} gives 3-4-5. The first number shown is '3', because the setting of parameter 1 to the value '2' (by the first unnamed parameter) is overwritten by the later direct assignment of the value '3' to parameter 1. Similarly, the direct assignment of the value '1' to parameter 3 is later overwritten by the third unnamed parameter.

When parameters do not expand

MediaWiki version: 1.6 (for parameters defaults)

Parameters do not get expanded when they are inside nowiki tags or XML-style extension tags. Thus, the following will not work within a template, because the parameter is not expanded:

 <myextension xparam={{{tparam}}}> ... </myextension>
 

More than three opening braces

In the case of more than three opening braces the last three are interpreted as parameter braces. If there is no matching triple of closing braces the last two opening braces are taken as braces for a template or parser function.

Thus {{{{a}}}} is parsed as { {{{a}}} }, e.g. {{{{t1demo|1}}}} gives "{1}", while {{ {{t1demo|1}}}} gives Template:Start1end and {{{{t1demo|1}} }} gives also Template:Start1end. Interestingly {{{{t1demo|1}} }} {{{5}}} gives Template:Start1end {{{5}}}.

Furthermore, {{{{{a}}}}} is parsed as {{ {{{a}}} }}, e.g. {{{{{abc|tc}}}}} gives "in".

Thus if an expression for a parameter name starts with a template or parser function a blank space is needed after the third brace, e.g. {{{ {{#if:x|tc|ab}}}}} gives the value of {{{ tc}}}, while {{{{{#if:x|tc|ab}}}}} gives "in" (using the default value tc of parameter #if:x, and ignoring "|ab").

With 6 braces, e.g. {{{{{{a|b}}}|c}}} gives c.

Monitoring parameter usage

To monitor the usage of a parameter of a template (in the case that many pages use the template), this template can call an auxiliary template of which the name depends on whether the parameter is defined. The possible auxiliary templates need not exist, if they are e.g. used as parameter value of Template:voidd (talk, links, edit), to avoid displaying anything (with the new preprocessor Template:void (talk, links, edit) cannot be used for this anymore). Applying "What links here" to the possible auxiliary templates shows which pages use the template with the parameter, and which pages use the template without the parameter. This parameter usage monitor facility should preferably be built into the template when creating the template or introducing a new parameter. If it is done afterwards "What links here" may not show a page until it has been refreshed by an ordinary or dummy edit or purge.

Applications of monitoring parameter usage include:

  • check where the parameter has not yet been specified, in order to add it
  • check where a parameter is used that is renamed, in order to change the template calls
  • check whether a parameter is used before abolishing it
  • when a template has been changed with respect to processing a particular parameter, check the pages which use the parameter (or some of them) to see if things work as desired.

In a similar way an auxiliary template can be called for a "template / parameter / parameter value" combination or "template / parameter / parameter value range" combination. "What links here" then shows which pages use the template with this parameter value, or with the parameter in the given range.

See m:Template:T optional parameter demo (backlinks, edit).

Template tag lay-out

To have a desired template tag lay-out, especially in the case of many parameters, additional dummy parameters can be used with a newline, spaces, and/or comments. In the case of unnamed parameters, this means that some parameter numbers are not used in the template content, so that their values, present in the template tag, do not affect the rendering of the template. For example, using Template:t3d containing "{{{1}}} {{{2}}} {{{3}}}<br /> {{{5}}} {{{6}}} {{{7}}}<br /> {{{9}}} {{{10}}} {{{11}}}<noinclude>[[Category:Demo template]]</noinclude>",

{{t3d |a|b|c| 1
      |d|e|f| 2
      |g|h|i| 3
}}

gives:

a b c
d e f
g h i

If parameters are named, dummy parameters can easily be inserted at any time. If they are unnamed, then, to avoid renumbering, one can insert named parameters: any text including an equals sign will do, if the text on the left is not one of the parameter numbers: this text is interpreted as the name of an unused parameter, hence ignored.

Example:

Using template:Chess position ( talk edit history links )

{{chess position|=

 8 |rd|nd|bd|qd|kd|bd|nd|rd|=
 7 |  |pd|pd|pd|pd|pd|pd|pd|=
 6 |pd|  |  |  |  |  |  |  |=
 5 |  |  |  |  |  |  |  |  |=
 4 |  |pl|  |  |  |  |pl|  |=
 3 |  |  |  |  |  |  |  |bl|=
 2 |pl|  |pl|pl|pl|pl|  |pl|=
 1 |rl|nl|bl|ql|kl|  |nl|rl|=
    a  b  c  d  e  f  g  h

|30}}

which gives

8 rd nd bd qd kd bd nd rd
7 pd pd pd pd pd pd pd
6 pd
5
4 pl pl
3 bl
2 pl pl pl pl pl pl
1 rl nl bl ql kl nl rl
a b c d e f g h

In this example, the 1 to 8 row numbers and a to h column numbers (as well as their surrounding spaces and newlines) in the parameter list are hidden within a dummy parameter (with an empty name before the equal sign).

The template generates a HTML table where each cell contains an image whose name is dynamically generated from the 64 first automatically numbered parameters (there are intermediate parameters within the numbered list, but as these dummy parameters are named explicitly, they don't increment the parameter number used to generate default parameter names. So the parameter with autogenerated name "1" effectively contains the "rd" value).

The template is then called with a parameter list that contains:

  • 65 parameters automatically named from "1" to "65" (64 parameters for the cells content, and the 65th for the image width),
  • and a dummy named parameter (whose name is an empty string, and whose effective value results from the last assignment with the chessboard column names a to h and the surrounding spaces and newlines), which is not used in the internal template content.

Note also that all parameters are trimmed, so the parameter with autogenerated name "9" (at position a7 on the chessboard above) is assigned the empty string value.

Relative name for transcluded page

A page A can transclude a subpage A/B using {{/B}} or, with more control over the name of the page to be transcluded, this name can be constructed from {{PAGENAME}}.

This allows copies of the same wikitext in different pages to transclude different pages. Thus for example, the same wikitext, adapted from [3], containing a list of calls {{/lang|..}}, can be used in various ways on different pages, for example m::List of Wikipedias/lang/demo‎ (talk, backlinks, edit) and m::List of Wikipedias/local names‎ (talk, backlinks, edit), by varying the content of the subpage. A transcluded page need not use all the specified parameters. Two pages can share the same transcluded page using a redirect.

Template page

Without noinclude and includeonly parts the following are identical:

  • the rendering of the wikitext of the template (this is on the template page, and would be the same in other pages with that wikitext, except for page-dependent variables)
  • the rendering of the template on a page that calls it without parameters

Thus the defaults are shown, e.g. Template:T 1 containing "test<noinclude>[[Category:Demo template]]</noinclude>" shows the same as {{t 1}}: "test".

Template page if no defaults have been specified

In simple cases this corresponds to treating the parameter tags as ordinary text, for example:

"{{t2demo}}" (using Template:t2demo containing start-{{{1}}}-middle-{{{2}}}-end<noinclude>[[Category:Demo template]]</noinclude>) gives start-{{{1}}}-middle-{{{2}}}-end

Similarly, if part of the parameters is undefined, only those show up as {{{parameter number or name}}}.

However, often the rendered page produces a seemingly arbitrarily mutilated version of its content:

  • #expr and #ifexpr applied to an expression containing a parameter tag without default produces an error message. For example, a template that doubles parameter {{{1}}} with the wikitext {{#expr:2*{{{1}}}}} gives Expression error: Unrecognised punctuation character "{".

For parameters without default a workaround is less needed because the result in the case a parameter is undefined is of limited use anyway. If one wants it anyway one can put nowiki tags around the parameter; for the first example this gives "{{{1}}}p".

Less surprising, but nevertheless limiting the usefulness of the result are:

  • #if applied to a parameter tag without default produces the then-part, the else-part is not shown.
  • #ifeq typically produces the else-part only.
  • Variable tags are not shown, but evaluated.
  • A switch typically shows the default only.

In such cases includeonly can be used to avoid uninformative and messy rendering on the template page, but either way a disadvantage during template development is that preview does not (meaningfully) reflect changes in the parts of the page outside the noinclude tags (i.e. the included parts). Therefore it can be useful to provide representative default values, even if that is only done temporarily during development of the template.

With noinclude an informative template page can be produced, containing more demos and test cases than just the single default set. Typically, the noinclude-part of a template page contains examples including or substituting the template. Changes in the working of the template (i.e. changes outside the noinclude-part) are not yet effective in these examples in preview and, in the case of substitution, in "show changes". However, they are reflected in the rendered page after saving.

Some formatting aspects may show up which are not readily seen from the edit box.

A parameter value depending on parameters

As mentioned above, if a parameter is left undefined, the triple braced parameter name in the result does not function as a parameter if the page is called as a template from another page; if it should, do not omit the parameter value but specify it in terms of a parameter of the calling page; compare:

  • {{t2ademo|b}} (using Template:t2ademo containing {{t2demo|a}}<noinclude>[[Category:Demo template]]</noinclude>) gives start-a-middle-{{{2}}}-end
  • {{t2a1|b}} (using Template:t2a1 containing {{t2demo|a|{{{1}}}}}<noinclude>[[Category:Demo template]]</noinclude>) gives start-a-middle-b-end.
  • Similarly, {{t2a2|b}} (using Template:t2a2 containing {{t2demo|a|2={{{1}}}}}<noinclude>[[Category:Demo template]]</noinclude>) gives start-a-middle-b-end. See also below.

The most straightforward way of expressing a parameter value in terms of a parameter is using the same name and making it equal, e.g. {{Lan is|lr=af|le={{{le}}}}} in Template:Lan is mr.

Empty vs. undefined

{{t2demo||a}} makes the first parameter equal to the empty string rather than leaving it undefined: it gives start--middle-a-end. By treating the second unnamed parameter as a parameter with the name "2", the first unnamed parameter can be left undefined.

Example: {{t2demo|2=a}} gives start-{{{1}}}-middle-a-end.

If the parameter is used in a tag like <font size> the default text may give invalid code that is conveniently ignored, rather than resulting in perhaps ugly code being rendered (but this may depend on the browser). See e.g. m:Template talk:Fontsizehttp://meta.wikimedia.org../../../../articles/f/o/n/Template_talk%7EFontsize_f8e1.html.

Parameter names (as opposed to template names) are case-sensitive, even with respect to the first letter, and spaces are distinguished from underscores. The empty stringhttp://en.wikipedia.org../../../../articles/s/t/r/String_%28computer_science%29.html#Formal_theory is also a valid parameter name, see m:Template:T empty string as parameter namehttp://meta.wikimedia.org../../../../articles/t/_/e/Template%7ET_empty_string_as_parameter_name_843e.html.

Parameter 02 is distinguished from parameter 2: using Template:t pl0 containing "[[:Template:T pl0]]", {{t pl0|5|6|7}} gives Template:T pl0

Note that parameters in the system messages (MediaWiki namespace]] are written differently: as $1, $2, etc.

msgnw

The prefix msgnw (short for "message, nowiki") is used to display within a page, more or less, the wikitext of another page. Differences are:

  • numbered and unnumbered lists are rendered as such instead of displaying # or * signs
  • (with the new preprocessor) comments are removed
  • a single newline is displayed as a blank space (this is especially disturbing the format of the wikitext of tables, and occurs even though newlines are significant in wikitable syntax)

This function has been used for displaying the wikitext of a template which is active on inclusion. However, with the introduction of noinclude tags, msgnw displays a mix of that with wikitext for rendering the template page itself, with these and includeonly tags.

For example, for m:Template:msgnw demo (backlinks, edit):

{{msgnw:Msgnw demo}} gives [[:Template:Msgnw demo]] [4]Template:Xpd/

(in the expanded wikitext, as seen with ExpandTemplates, the characters <>'[]{|& are replaced by codes).

Usage

A template is useful for any text for which one wants a copy in two or more pages, and there is no need for each copy to be edited independently to adapt it to the page it is in. Since parameters can be used, versions may to that extent even be different, and parameter values can be edited independently for each. Templates are not only convenient, but they can also "force" a useful uniformity. See also Subroutine#advantages of subprogramshttp://en.wikipedia.org../../../../articles/s/u/b/Subroutine.html#advantages_of_subprograms.

A template can also provide structure (e.g. a table structure, colors, and other formatting) while the content varies (fully or partly) through parameters and variables.

A template can also carry out computations, comparisons, etc. using ParserFunctions, where the result(s) vary again through parameters and variables. See e.g. m:Category:Mathematical templates.

Typical applications are:

Various combinations are possible. E.g., the last two could be combined, so that e.g. every language version of Wikipedia has the same Infobox Countries template (for each project a copy, because the template mechanism can not import across projects), which has parameters for the data, and refers to templates with translations of standard terms.

See also Help:Advanced templates.

Composite pages

The wikitext of a page may (partly or fully) consist of tags for the inclusion of component pages. The "templates" are not necessarily in the template namespace, and may be more or less self-contained pages by themselves. A disadvantage of putting the components in the template namespace is that the component page may, by itself, be of a nature that it belongs in e.g. the main namespace, while the prefix would suggest otherwise; also the prefix would clutter the pagename.

Examples are:

This allows the user the choice between viewing the component pages separately or combinedly. One may want to view a page separately if one has a slow connection; also sometimes people have sentimental reasons for having a separate page about a topic, e.g. a village. Viewing the combined page is much more convenient if there are many small component pages; even if a subbtopic page does not provide additional info, if it exists anyway, and is linked to, it is useful to display the content (making clear that the whole content is shown), it saves the trouble of checking the contents by following the link.

In the latter case the search function of the browser can be used for searching in the combined page. Similar to the section editing feature, it allows editing a component page; however, there is no possibility to have the combined wikitext in the edit box.

Edit history, recent changes, watching pages, and "what links here" work separately for the component pages and the composition page, not for the composite page. Related changes works for the component pages and for the composite page. Page protection can be set for selected component pages and for the composition page, not directly for the composite page.

The talk page of a composition page is used to talk about the composition and the page in general, and could in addition be a composite page of the talk pages of the component pages.

A composite page has an integrated TOC and section numbering; the numbering is not reset for each component page.

Editing a section of a component page can be done directly from the composite page, see editing sections of included templates. After saving, one ends up at the page for the component page to which the section belongs.

On projects with the interlanguage link feature the composite page shows the combined interlanguage links of all component pages, hence possibly multiple links for one language or even for one page.

For easy access to the component pages, links to them on the composite page (for example by self-links on the component pages) are convenient. Alternatively, access is through section editing, or, if the component pages are in the template namespace, through the list of templates called from the composite page, at its edit page.

Conversely, for easy access from a component page to the composite page(s) that call(s) it (if there are not too many of them) it is convenient to link the component page to them (on a composite page one becomes a self-link).

See also w:Wikipedia talk:Template namespace#transcluding prose.

Pages with a common section

A section on the relationship of the subjects A and B, or a subtopic equally relevant for A as for B, can be put both in page A and in page B, by making it a separate page C, called as a template from A and B.

Remarks:

  • For readers reading both A and B, it is useful that the duplication be indicated by a message or a special lay-out; otherwise it is confusing and inconvenient. One can for example use m:Template:common section (backlinks, edit).
  • After saving one ends up viewing the template page. For easy access to the calling pages it is convenient to link the called page to them (on a calling page one becomes a self-link). This may well be integrated in the message about the duplication. It is even more convenient than the two-step link as shown above.
  • The section level of the embedded section(s) has to be the same in each embedding page. The same applies to lay-out and style.
  • Pages like C can be put in
    • the same namespace as A and B; advantage:
      • the kind of content of C is the same as that of A and B
    • the template namespace; advantages:
      • C appears in the list of templates called from A and B, at their edit pages
      • C by itself may not satisfy the standards for pages in the namespace of A and B, such as providing context (however, the message about the duplication explains it)

Examples:

For various remarks which also apply here, see also the previous section.

Repetition within a page

For a succession of similar pieces of content, as in a list, a computer program would use a loophttp://en.wikipedia.org../../../../articles/c/o/n/Conditional_branching.html#Loops. What comes closest in MediaWiki is putting the loop body in a template, and calling the template repeatedly, usually with a varying parameter value. This is somewhat primitive for a loop:

Example:

  • Template:List of Languages - the "loop body" is in Template:Lang def; compared with putting the content of the latter directly in the list the advantage is that the variable part (the value of "code") occurs once each time in the code, although it is used twice. This is important because the fixed part of the list item code can be copied while the variable part is typically inserted manually.

The list of template calls can be in another template, with the name of the called template equal to or depending on a parameter, see e.g. m:Template:Do for every Dutch municipality (backlinks, edit).

For repetition of the same text the loop body can be a parameter, e.g. Template:5x (talk, links, edit).

A double loop is achieved by a second template that repeatedly calls the first. Similarly for a triple loop, etc. See e.g. Template:ld (backlinks, edit), Template:l2d (backlinks, edit), and Template:l3d (backlinks, edit).

An example where the same template is used for different loop levels is m:Template:Loop 2 (backlinks, edit). Because the software has a built-in protection against infinite nesting (if there is, there will be an error e.g. Fatal error: Maximum execution time of 30 seconds exceeded in /w/includes/Parser.php on line 775), a redirect is used for each level. The number of levels that the template can handle is determined by the number of parameters specified in the two template calls it comprises (because going up a level requires an extra parameter) and the number of existing redirects.

Similarly Template:Lanlp 1 is used for both the inner and the outer of a double loop. Adding an item (here a language) adds to each row and also adds an extra row.

Providing effective repetition without repetition of similar template calls in the wikitext

A technique for repetition of similar template calls without actually putting this list in the wikitext is demonstrated in template:for ( talk edit history links ), and a more primitive method described below.

Example (using Template:t2demo containing "start-{{{1}}}-middle-{{{2}}}-end"):

{{for loop|; |call=t2demo|pc1n=2|pc1v=constant|abc|def|ghi}} gives:

start-abc-middle-constant-end; start-def-middle-constant-end; start-ghi-middle-constant-end

Description of the old m:Template:List of template calls (backlinks, edit):

For an arbitrary template with up to three nameless parameters, it is equivalent to calling the template repeatedly, with the first parameter varying, and the possible other parameters fixed: one specifies the name, the values of the fixed parameters, and the list of values the first parameter should have in consecutive template calls, with a sequential number each, and ending with "end". The technique requires redirects like m:Template:List of template calls 3 (backlinks, edit), as many as the maximum number of repetitions.

If e.g. the second parameter varies, or two parameters, then a similar template can be made, but each version requires its own set of redirects.

Example (using Template:t2demo containing "start-{{{1}}}-middle-{{{2}}}-end"):

{{List of template calls|t2demo|constant||abc|1|def|2|ghi|end|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||}}

gives (see the master copy m:Help:Template#Repetition within a page):

Template:List of template calls

The empty parameters are needed in accordance with the maximum number of parameters the repeated template can have (currently three) and the maximum number of repetitions. Putting more empty parameters than needed at the end does not matter, but the number of empty parameters in the beginning of the list should be correct.

See also m:Help:Recursive conversion of wikitexthttp://meta.wikimedia.org../../../../articles/r/e/c/Help%7ERecursive_conversion_of_wikitext_4869.html.

Ambiguity of a reference to "this page"

If a page is included in another page, a reference to "this page" on the included page is ambiguous. Use noinclude or includeonly tags depending on what is meant. Alternatively, mention the page name explicitly, without using {{PAGENAME}}.



Noinclude, includeonly, and onlyinclude

This feature is not available before version 1.6. These features are applied as nesting pairs, or 'Blocks', as it is said they enclose the material so that they can be said to begin and end a block of wikitext (code).

noinclude blocks

Anything between <noinclude> and </noinclude> will be processed and displayed only when the page is being viewed directly; it will not be included or substituted. Possible applications are:

  1. Categorising templates, see template documentation.
  2. Interlanguage links to similar templates in other languages.
  3. Pages in the MediaWiki namespace.
includeonly blocks

The converse is <includeonly>. Text between <includeonly> and </includeonly> will be processed and displayed only when the page is being included. Applications include:

  1. Adding all pages containing a given template to a category, but not the template itself.
  2. Avoiding messy rendering on the template page, e.g. {{#expr:{{{1}}}}} gives Expression error: Unrecognised punctuation character "{" [6]Template:Xpd/.

Note that spaces and newlines between the general content and the tagged part belong to the general content. If they are not desired the include tag should directly follow the content on the same line:

<noinclude>this is </noinclude>fine<includeonly>, closing tags are
</includeonly><noinclude>
less critical, but must be specified.</noinclude>
nesting

Nesting an includeonly block within a noinclude block (or vice-versa) is legal but pointless.

onlyinclude blocks

With <onlyinclude>wikitext</onlyinclude> on a page, the display of the wikitext so surrounded and the rest of the page (except includeonly parts) is rendered on the page itself normally (note: this means interwiki translation links will behave as normal external links, unless they are further bracketed by <includeonly>). The demo page below holds a full screenful of text and code, including several includeonly blocks as well as a single onlyinclude block as a demonstration. It is advisable to look at that page in edit mode.

However, in transclusion, the page gives only the parts within onlyinclude blocks. Thus, using m:Help:Template/onlyinclude demo (talk, backlinks, edit), on Meta {{Help:Template/onlyinclude demo}} gives Help:Template/onlyinclude demo; it does not even transclude other blocks which are defined as includeonly parts, unless such are also within the onlyinclude block. So on a page with onlyinclude tags, text within includeonly tags is never rendered, i.e., it is reduced to wikitext comment. See also m:Help:Template/onlyinclude demo 2 (talk, backlinks, edit).

Caveats on splitting and interworkings

Attempts to nest split pairs of these tags, or the similar <nowiki> and </nowiki> pair, won't work as expected.

If say <nowiki> begins within the general page content, or in a "noinclude" part, or in an "includeonly" part, then it also has to be closed within the same part.

The code ~<includeonly>~</includeonly>~~ will be displayed as ~~~ when the template is not included, ~~~~ when the template is included, but it will only be expanded as the active user when the template is subst'd, which is to say when it has been joined within the same block once again.

Wiki markup at the beginning of a template

If the first included character of a template is one of the Wiki markup characters :;*#, then it's interpreted as being at the beginning of the line (even when the template call is not).

To avoid this effect use <nowiki>#</nowiki> or a numeric character reference (NCRhttp://en.wikipedia.org../../../../articles/n/u/m/Numeric_character_reference.html) or HTML entity like say &#58; for a colon. This NCR is also useful in conjunction with definition lists.

Substitution

Main article: Help:Substitution

Putting "subst:" after the double opening braces causes an automatic conversion of wikitext when the referring page is saved: the subst tag is replaced by the wikitext of the template, with the parameter values substituted for the parameters.

For optional multi-level substitution of templates add a substitution parameter with the empty string as default, e.g. {{{substp|}}}, after the opening braces in all calls of templates, parser functions and variables in templates, and add parameter definitions of the form "substq={{{substr|}}}" in all template calls within templates. Note that the use of multiple substitution parameters allows selective substitution. Maximum flexibility is obtained by making them all different. Sometimes a little less flexibility is needed; e.g. there may be a group of parser functions in a template for which it is sufficient to be able to choose between substitution of all or none in the group.

To reduce, in the wikitext, undefined parameters with default to the defaults themselves, use the alternative way of specifying a parameter default.

Redirection

When a page called for inclusion is a redirect page, the redirect target is included instead. As usual, a double redirect does not work.

A page that consists of nothing else than the inclusion of another page as a template, shows similarities to a redirect to that other page, but also many differences, including:

  • the result has as header the name of the referring page
  • there is no redirect message
  • the buttons such as edit (for editing the whole page), watch, talk, history, "what links here", and "last modified", etc., refer to the referring page (to go to the target page, a section edit link can be used, from there the whole page can be accessed)
  • the referring page is in the same categories as the target page, except when includeonly and/or noinclude tags are used
  • "double redirects", with one or both being this kind of "pseudo-redirect", work.

Compare m:Help:Template namespacehttp://meta.wikimedia.org../../../../articles/t/e/m/Help%7ETemplate_namespace_a112.html with m:Help:Template namespace - demo of alternative for redirecthttp://meta.wikimedia.org../../../../articles/t/e/m/Help%7ETemplate_namespace_-_demo_of_alternative_for_redirect_d9d0.html.

In a page that in turn includes such a referring page there is no difference.


Note that embedding works for all pages where redirecting works, and it also fails for all pages where a redirect won't work.

Self-transclusion

A page can transclude itself, but is protected against an infinite loop: the transclusion in the transcluded copy of the template is replaced by the bolded pagename. See m:Help:Self-transclusion demo (talk, backlinks, edit) and m:Help:Self-transclusion demo 2 (talk, backlinks, edit).

Transcluding on page A page B redirecting to page A allows more repetition, see m:Help:Self-transclusion demo with redirect (talk, backlinks, edit) with m:Help:Self-transclusion demo redirect (talk, backlinks, edit).

If due to the use of braces hidden in a template (see m:Help:Recursive conversion of wikitexthttp://meta.wikimedia.org../../../../articles/r/e/c/Help%7ERecursive_conversion_of_wikitext_4869.html) the saved wikitext of a page contains a substitution call to itself, then on the next save the substitution is applied for one level; the transclusion in the transcluded copy of the template is replaced by a link to the pagename. Thus it becomes a self link, i.e., it becomes bolded text with immediately following characters also bolded. This time the link is followed in the wikitext by the hidden message "<!-- WARNING: template loop detected -->"; see [7]; this edit was automatic by edit/save without making a change in the wikitext oneself.

Parsing braces

If some braces are "hidden" in a template, as in m:Template:lb (backlinks, edit), then parsing of pairs of double and triple braces is based on visible braces only. In the case of partial substitution, first parsing is done for the purpose of substitution, then parsing is done again for rendering:

  • {{t1|{{lb}}tc}}}} gives {{[[Template:Template:Lbtc|Template:Lbtc]]}}}} - the last-but-one pair of closing braces is taken as closing braces of template:t1 ( talk edit history links )
  • {{t1|{{subst:lb}}tc}}}} gives the wikitext {{t1|{{tc}}}} rendered as {{in}} - after substitution the last pair of closing braces is taken as closing braces of t1
  • {{subst:t1|{{subst:lb}}tc}}}} gives the wikitext start{{tcend}} rendered as startTemplate:Tcend - the last-but-one pair of closing braces is taken as closing braces of t1 for both substitutions
  • {{subst:subst}}t1|a}}, substituting template:subst ( talk edit history links ), gives the wikitext {{subst:t1|a}} rendered the same; in the next edit the wikitext is converted to "startaend".
  • {{subst:tsubst 1|a}}, substituting template:tsubst 1 ( talk edit history links ): ditto.

With parser function #if instead of template:t1:

  • {{#if:x|{{lb}}t1|a}}|b}} gives Template:Lbt1|b}} - the last-but-one pair of closing braces is taken as closing braces of #if.
  • {{#if:x|{{subst:lb}}t1|a}}|b}} gives the wikitext {{#if:x|{{t1|a}}|b}} rendered as {{a}} - after substitution the last pair of closing braces is taken as closing braces of #if.
  • {{subst:#if:x|{{subst:lb}}t1|a}}|b}} gives the wikitext {{t1|b}} rendered as {{b}} - the last-but-one pair of closing braces is taken as closing braces of #if for both substitutions.
  • {{subst:#if:x|{{subst:subst}}t1|a}}|b}} gives the wikitext "{{subst:t1|b}}" rendered the same: "{{subst:t1|b}}" (the substitution phase is finished; the ordinary template expansion phase ignores substitution calls); in the next edit the wikitext is converted to "startbend".
  • {{subst:#if:x|{{subst:#if:x|{{subst:subst}}t1|a}}|b}}|c}} gives the wikitext "{{subst:t1|c}}" rendered the same: "{{subst:t1|c}}".
  • {{subst:#if:x|{{subst:tsubst 1|a}}|b}} gives the wikitext "startaend". Apparently there is a substitution phase of parameter expansion resulting in the parameter value "{{subst:t1|a}}", and another substitution phase for the substitution of #if, taking the parameter value not as plain text, but interpreting the "subst:" in it again.

See also m:Help:Recursive conversion of wikitexthttp://meta.wikimedia.org../../../../articles/r/e/c/Help%7ERecursive_conversion_of_wikitext_4869.html.

Comparison of linking and embedding

Linking and embedding have in common:

  • if the page does not exist, a link to the edit page is shown; the links are identical if it is not a piped link; the link does not show parameters and does not show whether, after creation, the new page will be linked or embedded.
  • the name can depend on variables and parameters

Predefined templates

Variables and parser functions can be considered predefined templates. They do not have a page that defines in terms of wikitext what they do, because their action is something extra that cannot be constructed from more basic wikitext functionality.

Some additional differences:

  • Parser functions use ":" instead of the first "|".
  • An edit page does not list predefined templates used on the page.
  • No "What links here" is available for predefined templates, to find the pages where they are used.
  • Apart from #switch, predefined templates don't allow you to define named parameters, and therefore equal signs generally have no special effect, comparison:
    {{ #if: not blank | p=q }} gives p=q
    {{ if || not blank | p=q }} gives {{{3}}}

Ordinary and predefined templates have in common that their parameter values can depend on ordinary and predefined templates. In the case of named parameters, the names used in the template call can also depend on ordinary and predefined templates. This applies also for the named parameters of #switch.

Template expansion

Expansion of wikitext can be relevant even if the wikitext resulting from these subevaluations cannot have effect on the overall wikitext, because the expansion can have Side effect (computer science)#side effectshttp://en.wikipedia.org../../../../articles/s/i/d/Side_effect_%28computer_science%29.html#side_effects:

  • Subevaluations producing links add on the target page to the list of incoming links (What links here), based on the pagelinks table, even if there is no link on the resulting page.
  • Subevaluations involving template calls add on the template page in "What links here" and on the edit page of the page concerned to inclusion items, based on the templatelinks table.
  • Some extensions may perform some action during a subevaluation, e.g. with VariablesExtension a subevaluation may involve assignment of a value to a variable.

In the case of #ifexpr etc., either the then-part or the else-part is expanded, not both. Also the wikitext for the value of an unused template parameter is not expanded.

See also ParserFunctions#Code_execution.

Templates as table pieces

Tables using wikitable syntax can have pieces in templates. Tables using HTML syntax can not, by default. Thus, if you have a table row like

 |1||2
 |-

in a template called "Row1" and a table row like

 <tr><td>1</td><td>2</td></tr>

in a template called "Row2", and you have tables like

 
  {| border="1"
  |a||b
  |-
  {{Row1}}
  |c||d
  |}
  

and

 
  <table border="1">
  <tr><td>a</td><td>b</td></tr>
  {{Row2}}
  <tr><td>c</td><td>d</td></tr>
  </table>
  

You will obtain:

a b
1 2
c d

and

<tr><td>1</td><td>2</td></tr>

a b
c d

But if you set the variable $wgUseTidy HTML table will work too. It's false by default, but it is true in most Wikimedia projects.

See also conditional table row.

Templates in different versions of MediaWiki

Version 1.6

  • More magic words and the parameter default mechanism were added.
  • <noinclude> and <includeonly> (see above) were added.

Version 1.5

Version 1.4

  • Including the same template more than five times in the same page works from version 1.4, now on all Wikimedia sites. Also new was that subst can be used with parameters.

Version 1.3

Version 1.2.6

  • In MediaWiki version 1.2.6, make a page MediaWiki:mytemplate and refer to it with {{msg:mytemplate}}. In this version parameters are not possible.
  • Compatibility with 1.3, in the sense of having the content in Template:mytemplate, is possible with a redirect from MediaWiki:mytemplate to Template:mytemplate on the 1.2.6 project.

History

When ParserFunctions were not available yet, multiple assignments of parameters with the same name (and thus allowing parameter overrides) were ingeniously used to perform branching, e.g. in the now deleted en:Template:If defined.

Revision history of pages containing templates

Pages in the stored page history consist of wikitext with possible references to templates and images. When viewing an old version of a page, these refer to the current versions of the templates and images, if these still exist. Thus the former composite page is not reconstructed.

Other pages not primarily meant for direct viewing

Pages not primarily meant for direct viewing include, apart from templates:

Notes

  1. ^ Actually, for efficiency the result of the expansion may be cached and reused. The point is that when viewing the page after a change of the template, we see the new version of the page.
  2. ^ Note that these external Wikia projects are NOT hosted and managed by the Wikimedia Foundation.

See also


edit

Wikipedia-specific help

See also Wikipedia:Template messages.

Troubles with noinclude

The noinclude-tag, from MediaWiki language version 1.6, coded as "<noinclude>" does not function as might be expected. Although the tag name might imply that the text is omitted ("not included"), the opposite is happening during processing. The nonincluded text is buffered, behind the scenes, for potential error messages, and is accumulated from all templates that are processed, with the accumulation growing each time a template is transcluded in a page.

To handle the condition of a missing slash end-tag (missing "</noinclude>"), all of the nonincluded text is included in the processing buffers, and upon end-of-file, all of the non-included text will be thrown into the page buffer. This "error-reporting" tactic requires that every character of non-included text cannot be omitted, but must be, instead, carefully included for display when an error condition occurs.

Because the "nonincluded" text (after "</noinclude>") is painstakingly included in the processing buffers, unwanted text should be kept in other files, such as a "/doc" sub-file to describe template performance. Excessive nonincluded text can clog the processing buffers and cause templates to go haywire and block the further processing of if-expressions and similar language within other included templates.

Descriptive text has already been split from some common templates, such as vertical-bar templates Template:! and Template:!! (back on 19-Aug-2006 & 4-Oct-2006), to avoid clogging limited resources. Such common templates use "{{template doc}}" to display the related "/doc" sub-files, when viewed as non-included pages.

Summary: In spite of the noinclude-tag ("</noinclude>"), every single character will be kept and retained internally, from all templates used, for the duration of template processing for a page.

Interwiki links clog templates

Similar to other text in a file, any interwiki language-links (such as "[[de:deutsche Sprache]]" also fill the template-processing buffers, detracting from resources available to process multiple templates. For most templates, the clogging effects of interwiki language-links are minimal; however, with heavily-used templates (such as vertical-bar exclamation "{{!}}"), the cumulative effects, of retaining many "nonincluded" interwiki links, can kill template processing. In actual tests, as few as 14 interwiki links were too many for a map-definition template used by "Template:Location_map_many". As a result, interwiki links should be moved to the associated "/doc" subfile for a heavily-used template.

Summary: for most templates, used only a few times per page, the interwiki language-links are not a problem; however, for multiply used templates, the interwiki links can be fatal for repeated template usage within a page.


This page is a copy of the master help page at Meta (for general help information all Wikimedia projects can use), with two Wikipedia-specific templates inserted. To update the main text, edit the master help page for all projects at m:Help:Template. For Wikipedia-specific issues, use Template:Ph:Template (the extra text at the bottom of this page) or Template:Phh:Template for a Wikipedia-specific lead (text appears at the top of this page). You are welcome to replace the full wikitext of this page with that of the master page at Meta at any time. To view this page in other languages see the master page at Meta.