The template namespace is the namespace of pages with prefix "Template:".[4] For example: Template:Tc. The namespace in this example is "Template". The page name is "Template:Tc".[5]

One way of making a template is typing the tag first, and then following the red link.

One can call a template that calls another template. If a template calls itself directly or indirectly ("recursion"), the second-level inclusion is replaced by a link (possibly a self-link), with the HTML error comment:

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

on a section edit page, the list of templates will not initially display; after pressing preview, only those templates used in that section will list; while on the section preview page, pressing preview again will update the list for the edits made, if any;

when editing an old version of a page, the list is first given for the current version of the page; after pressing preview, the list will only show the templates that were used in the old version; pressing preview again will update the list for the edits on the old version made in the current session, if any;

if the name of an embedded page is an expression, the current template name is shown. E.g.:

For the name of a page used as a template, whether in the template namespace or not, the regular rules apply, see Help:Page name. Thus, for a template in the template namespace, the part of the name after "Template:" is case sensitive except (on most wikis) for the first letter, and a blank space is the same as an underscore "_". Case sensitivity can be resolved through the use of redirects. E.g., A template is named "AdminAbbr"; if a redirect to the template is created, and named "Adminabbr", the template can then be called with either {{AdminAbbr}} or {{adminabbr}}. Assuming the template name or redirect is all in lowercase (or uppercase), if an editor wished to use a mix of uppercase and lowercase on a template name for clarity, they could then use the lc or uc parser functions, e.g., a template named "CURRENTINTERNETTIME" may be difficult to read for some editors, so rather than using {{CURRENTINTERNETTIME}} the editor could instead use {{ {{uc:CurrentInternetTime}} }}.

However, parameter names are case-sensitive, including the first letter, and spaces are different from underscores.

A template only works on a page in the same wiki. To use it in another wiki, one has to copy it to there. Bugzilla:1126 requests to lift that restriction, and allow interwiki use of templates.

The adjustments needed in the copy, to work on the other wiki, can be reduced by using {{SERVER}}, localurl, and generic namespace names, and writing links in a way that works on multiple wikis, 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 wiki. Therefore, when choosing template names, check which names are in use on other wikis to which people might want to copy the templates. Note that if a template is referred to by something like abc{{NAMESPACE}}, a wiki with different namespace names requires a different template name, or a redirect.

Transclusion across wikis, 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

Sometimes multiple wikis require pages which are partly the same and partly different. For example, on some wikis "m:" is used as interwiki link to Meta, and on some wikis "MetaWikipedia:". In this case a common wikitext can be used, calling wiki-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.

A template can contain parameters by putting a parameter name in three right and left curly brackets {{{ }}}.[6][7] The values are specified in the template call.[8][9] Parameters not only allow an editor to substitute unique text on a page, without changing the original template, but they may even control which action the template performs.

A template call can use named parameters and/or unnamed parameters, using one of the following forms (the number of parameters, here two parameters are used, can vary):

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

The defaults are optional, together with the pipe character "|" in front, see below.

For example:

Example 1

The Template:Weather page has the text:

The weather in {{{1}}} is always {{{2}}}.

An editor can then add the template {{Weather}} on several other wikipages.

If a parameter name as used in a parameter tag such as {{{3}}} or {{{3|stu}}} is a not too large positive integer, in the template call it can both be referenced explicitly with, as in 3=pqr, or implicitly by putting pqr in the third position among the unnamed parameter definitions.

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 Template:For. See also Help:Newlines and spaces; also, compare conditional whitespace.

If an unnamed parameter is unused it does not contribute to the preprocessor node count, while for each unused named parameter the count is 1. This is relevant in data templates containing data in the form of values of parameters of a variable inner template, see Help:Array.

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:

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.

The names of numeric parameters are compared as strings, not numbers. The parameter 02 is distinguished from the parameter 2: using Template:t pl0 containing "{{{1}}}{{{2}}}{{{02}}}", {{t pl0|5|6|7}} gives 56{{{02}}}

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

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, which is:<includeonly>start-{{{1|pqr}}}-end</includeonly>

Calling the template named t with a parameter value of "a", i.e.,

{{t|a}}

gives

"start-a-end".

Calling the template named t with a parameter value of " ", i.e.,

{{t|}}

gives

"start- -end".

Calling the template named t with a parameter value of "", i.e.,

{{t|}}

gives

"start--end".

Calling the template named t with named parameter 1=, i.e.,

{{t|1=no surprise}}

gives

"start-no surprise-end".

Calling the template named t with 1= after an unnamed parameter, i.e.,

{{t|no|1=surprise}}

gives

"start-surprise-end".

Calling the template named t with 1= before an unnamed parameter, i.e.,

{{t|1=no|surprise}}

gives

"start-surprise-end".

Calling the template named t and no parameter at all, i.e.,

{{t}}

gives

"start-pqr-end".

Calling the template named t and no named or unnamed parameter 1, i.e.,

The "{{t2demo||a}}" makes the first parameter equal to the empty string rather than leaving it undefined: it gives "start--middle- a -end", just like "{{t2demo|1=|2= a}}" gives output: "start--middle- a -end". By specifying parameter name "2" explicitly, the first unnamed parameter can be left undefined:

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

If the second parameter should not be trimmed it has to be unnamed, which means that we can assign the first parameter the empty string, but we cannot leave it undefined.

It is often convenient if assigning the empty string to a parameter has the same effect as not assigning any value to it, as the difference is somewhat abstract, and as mentioned, in some cases there is not even the choice. Also, for example "p=" may be put for convenience, to be filled in later, and/or meant to make explicit that the template has a parameter p, but at this time we do not give it a value.

Making emptiness and undefinedness equivalent can for example be achieved by exclusively using {{{p|}}}, not {{{p}}} and not {{{p|q}}} for a non-empty q, or for example using {{#if:{{{p|}}}|..{{{p}}}..|..}} (i.e., using {{{p}}} only in branches of branching functions where it is defined and non-empty).

If it is just for display, the equals sign = can be replaced by the HTML entity &#x3D; or &#61;: start- a=b -end.

The same example with "1= a=b " gives start-a=b-end.

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 "|" (vertical bar symbol, aka: pipe), 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 inside nowiki tags (<nowiki>...</nowiki>), or their HTML entity codes must be used: the "{" is "&#123;", the "}" is "&#125;", the "[" is "&#91;", the "]" is "&#93;". 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.

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 "|". The pipe symbol "|" can be replaced either with &#124; or with {{!}}, see the difference shown next. Using Template:t1demo containing "start-{{{1}}}-end<noinclude>
[[Category:Demo template]]</noinclude>", compare this "{{t1demo|a{{!}}b}}" giving "start-a|b-end", and this "{{t1demo|a&#124;b}}" giving "start-a|b-end" and "{{t1demo|a|b}}" giving "start-a-end". 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.

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.

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:templates|T sup]]</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. See also mw:Module talk:ArgumentPairs demo.

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, to avoid displaying anything (with the new preprocessor Template:Void 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.

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}}}",

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

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.

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 [2], containing a list of calls {{/lang|..}}, can be used in various ways on different pages, for example List of Wikipedias/lang/demo‎ (talk, backlinks, edit) and 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.

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: Unrecognized 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.

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:

Note that with ExpandTemplates (see the link) "Remove comments" should be on to get the real result, otherwise it shows also the comment <!--Msgnw demo-->.

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

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. An advantage of using {{doc}} is that if one would want to show the included part of the wikitext, the cluttering remainder of the wikitext is minimized.

There does not seem to be an automatic way to show the included wikitext. It requires copying that and putting it between <pre> tags (if it has multiple lines) or <nowiki> tags (if it is on one line, to get it inline).

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, they can also prevent the server doing duplicate work in the expansion of a page by reusing a parameter value that is expanded only once (like assigning a result to a variable or a dynamically valued constant in a computer program, and making multiple use of it); also they can "force" a useful uniformity. See also Subroutine#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.

provide cross-language portability of texts which are largely internationally the same, but contain some standard terms different in each language; the standard terms are replaced by {{..}} referring to template pages which have the same name but localised content in each language. This is applied in Wiktionaries for names of languages, terms like "noun", etc.; it is also applied for taxoboxes, see e.g. w:en:Template:Familia and w:fr:Modèle:Familia.

allow a composite image, composed of a table of images, to be specified by a template tag which itself has a corresponding table-like lay-out, see w:Template:Chess position and w:Template:Game of Go Position (the latter example also shows that the number of parameters a template can have is quite large, in this case 362). Newlines in parameter values provide the lay-out of the template tag, but they are not allowed in image names, therefore they are put within comment tags; alternatively, dummy parameters could be used on these positions.

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 wiki a copy, because the template mechanism can not import across wikis), which has parameters for the data, and refers to templates with translations of standard terms.

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.

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 subtopic 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 wikis 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).

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 Template:Common section.

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)

For a succession of similar pieces of content, as in a list, a computer program would use a loop. 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:

instead of "for i=1 to 5" we need to enumerate the values 1, 2, 3, 4, 5; on the other hand, this gives the versatility to use just as easily less regular values such as de, en, fr (collection-controlled loop).

repetition of code is minimized by the template, but the template call itself has to be repeated each time (but see also the next section)

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.

An example where copies of the same template are used for different loop levels is Template:Loop 2 (formerly a redirect could be used for each level, but that gives the error message "Template loop detected" now). 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 copies.

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 ( talkedithistorylinks ), and a more primitive method described below.

Templates can prevent the server doing duplicate work in the expansion of a page by reusing a parameter value that is expanded only once (like assigning a result to a variable in a computer program).

Example: "{{Population Dutch municipality by code|193}}" → "118943" [5] with preprocessor node count 871/1000000[13], post-expand include size 12/2048000 bytes, and template argument size 3/2048000 bytes (for these page counts[14] see w:wp:Template limits). Thus mainly the preprocessor node count is a concern (especially on a page with many of these high counts): a switch is used, therefore 2 is added for each case. This municipality is the last of the 430 in the list.

Rounding the number to three significant digits requires a parameter of the round operator that is computed from the number:

{{#expr:{{Population Dutch municipality by code|193}}round(2-floor(ln{{Population Dutch municipality by code|193}}/ln10))}} gives 119000, with a preprocessor node count of 1743[13]/1000000, a post-expand include size of 30, and a template argument size of 6. Thus the preprocessor node count is doubled, plus 1 for #expr.

Better is to use Template:Sigdig, because now the high count for the switch is not doubled:

{{sigdig|{{Population Dutch municipality by code|193}}|3}} gives 119000 with a preprocessor node count of 879, a post-expand include size of 24, and a template argument size of 16.

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}}.

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:

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. Using the test line:

When repeated below we get: Using Help:Template/onlyinclude demo, {{Help:Template/onlyinclude demo}} gives def. When that page is included, 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 Help:Template/onlyinclude demo 2 and its talk page.

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.

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.

When a page called for inclusion is a redirect page, the redirect target is included instead. As usual, a double redirect or broken 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.

If due to the use of braces hidden in a template (see Help:Recursive conversion of wikitext) 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.

If some braces are "hidden" in a template, as in template:lb ( talkedithistorylinks ), 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:

{{#if:x|{{lb}}t1|a}}|b}} gives {{t1|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 start-a-end - 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 start-b-end - 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: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.

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 | 2=abc }} gives 2=abc

{{ ifdef | not blank | 2=abc }} gives abc

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. Since everything before the first pipe can depend on ordinary and predefined templates, a difference is that in the case of a parser function this applies to the whole combination of name, colon, and first parameter: {{#exp{{1x|r:}}2*3}} gives 6, while {{t1{{!}}a}} gives {{t1|a}}. Another difference is that a blank space is allowed between the template name and the first pipe, but not between the parser function name and the colon: {{t1 |a}} gives start-a-end, while {{#expr:2*3}} gives 6.

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.

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.

It allows transclusion of a section of a page, where "section" is not necessarily a section in the sense of Help:Section, it can be any marked part of a page, even a non-contiguous part, and sections can overlap. It allows content that is reused to reside on some master page instead of in a separate template (with that content only, or a collection of that kind of content). For example, a population figure of a town can be in the wikitext of the town page, and be reused elsewhere in a table of towns, or conversely.

This provides integrated editing and an integrated edit history of the combination of specific and reused content on the master page. Note however that not having a separate edit history of a piece of reused content can also be a disadvantage.

"{{#lst:Help:Advanced templates|vartemp}}" → "In some cases, it may be useful for a template to call different templates depending on a variable or a passed parameter. This allows a type of branching that can be simpler than with ParserFunctions, though they are generally less versatile." [12]

An alternative that does not require the extension puts the sections (pieces of content) to be reused inside <onlyinclude> tags, or the rest is put in <noinclude> tags. {{#ifeq:{{{1}}}|k|k'th section}} can be used to select a section. Another method, which was for some time used in s:Bible (King James)/Philemon, makes each section the default value of a parameter; this allows selection of one or more sections by giving the parameters other than the corresponding ones the empty string as value. Thus the excluded sections have to be specified; to avoid making it cumbersome to select just one section the auxiliary template (code) is used.

These alternatives have no straightforward way of allowing overlapping sections.

Transcluding a page from the start to a specified position in the expanded wikitext can be done with #padleft without any preparation of that page. If one wants to control the exact end of the transcluded part, without a sentence or paragraph cut off, every time the first part of the page is edited the truncation parameter has to be adjusted.

↑This process is called transclusionhttp://en.wikipedia.org/wiki/Wikipedia:Transclusion. If a page is specially intended for this purpose it is called a template. In terms of programming languages, the wikitext of a page can be considered a stringexpression. In this view a template call is the call of a string function. The template page is the function body. The resulting string may are either be fixed or depend on parameters and/or variables. Other than in many programming languages the declaration of the function does not start with a formal parameter list, it consists of the function body only, which is a string expression for the result. See also compound document.

↑This is called a template call or template tag; it has two "braces" on either side of the template page name and doesn't include the "Template:" prefix. {{Template:Tc}} also works, but "Template:" is not necessary. The result is "{{tlc|...}}".

↑The potential difference between the wikitexts {{:The weather in London|a|b|c}} and [[Red link|The weather in London]], now giving The weather in London and The weather in London, is, of course, that after creation of the page the rendering of the first changes and that of the second remains the same, except for the color of the link. The two can be distinguished by the link target (which one may see in the browser in the status bar or a hoverbox), in the case of a piped link. Even with the same target, on wikis without case-sensitivity for the first letter one can recognize an ordinary link as such if the rendered name starts with a lowercase letter, because the rendering of the inclusion code shows the canonical page name: {{:the weather in Londona|b|c}} and [[the weather in London]] give The weather in London and the weather in London.

↑This prefix can be used in all languages, but the canonical prefixes in languages other than English include Vorlage, Modèle, Sjabloon, with colon (respectively, German, French, and Dutch); the site WikiFAQ calls it Snippet.

↑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.

↑A more technical explanation: 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 Template:T1demo only using parameter {{{1}}}, and giving start-start-pqr-end-end, transcludes templates tc and te only.

↑A parameter in a template is a placeholder for the parameter value specified in the template call. A parameter is also called an argument, e.g. in "template argument size".

↑This was the original further template up until 20:56, 19 June 2008, when much more complex formating was added, which is beyond the scope of this article.

↑Template parameters are called-by-value, and therefore input parameters only (see also the section "Template expansion"). 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.

↑The terms page count refers here to a count regarding a page, not a count of a number of pages. The term template limit is somewhat misleading since parser functions and even <nowiki> tags and section headers also contribute to some of the counts.

arg: - instead of including a page for given parameter values, this allows linking to a page for given parameter values. Syntax for parameter use: {{arg:parameter name|default}}. Syntax for linking: external link style with "&parameter name=parameter value" added to the URL.