From Teflpedia

A template is a page that is included in another page.

Transclusion in Media Wiki[edit]

Any page can be used as a template, all that is necessary is to put its title between two pairs of braces: {{namespace:pagename}}. When viewing a page with another page included in it, the template will appear exactly where code is located in the wikitext. The official term used when a template is put into a page is "transclusion".

For example, {{:Michael Lewis}} will transclude an exact copy of that page (when you alter the page, anywhere that transcludes it will also display the change) like so (without the lines above and below which have been added on this page) Note that in this example a blank space is left where namespace should appear because it is in "Main" namespace.:

As you can see, when transcluding an article like the above it's as if the exact wikitext was pasted into where the template is - you can't tell what is and what isn't a template by looking at the final article. It even appears in this page's table of contents.


Putting "subst:" after the double opening braces ({{subst:pagename}}) is called substitution. When the page is saved, the subst tag is replaced by the wikitext of the template, with the parameter values substituted for the parameters. N.B.: This means that the displayed content will not be changed if the template itself is amended.

Template space[edit]

Pages that are designed to be readily and repeatedly used are usually in the Template namespace. In the case of the template space the namespace does not need to be included inside the braces: {{pagename}}. For example, {{Boxword‎ }} is very commonly used on Help articles and is responsible for generating this box.


There are complications. Templates can have "parameters" which will affect the appearance or content.

When using a template with unnamed variables care must be taken.
If using just (say) variables 1 and 4 then use it as:

(see template:Cquote for an occasion when you will probably need to do this).

It will also be necessary to include "number=" if there are any equals signs (=) in the variable.

If or when you create a new template, especially if it's more than a simple transclusion, please include instructions on the template page itself. Render them safe using the <noinclude> </noinclude> tags around the instructions so they aren't transcluded.

Restricted characters[edit]

Restricted characters are those that have special meaning within MediaWiki's template syntax, such as:

= (used to assign parameter names)
|   (used to separate parameters)

To use a restricted character within a template parameter, transclude it from another template! Restricted characters are not restricted in templates, just in parameters.

Examples, in template parameter calls:

  • For "=" use {{=}} -- Template:= contains "="
  • For "|" use {{!}} -- Template:! contains "|" (Note that we use ! in this template name instead of | because | cannot be part of a page name.)
  • For "||" use {{!!}} -- Template:!! contains "||"

Selective transclusion[edit]

In order to transclude part of a page only, sections of a template can be blocked out with special <noinclude> tags. When placed around a block of text, <noinclude>like so<noinclude>, the text will be exempt from transclusion. This is often used for explanations of how to use the template. It was used in the example ({{:Michael Lewis}}) at the top of the page to avoid carrying a "stub" template and a category over.

Content can be made to show up only in transclusions by using <includeonly> tags. This might be used to put the receiving page into a particular category without putting the template itself into that category: <includeonly>[[category:greek]]</includeonly> will put the receiving page into the (non-existent) category Greek.

The last option is the <onlyinclude> tag. If this tag is used, only the content it encloses will be transcluded but it will also show on the Template page itself.

Making a template[edit]

Templates are made like any other Media Wiki page but are put in the template namespace. The easiest way to learn about templates is to copy and alter an existing one - testing the results on your user page or in a sandbox before placing it all over the site, of course. This can be easily done with the many "userbox" templates that adorn many userpages.


Text between noinclude tags on a template wont be transcludeded--it will only show on the template page itself. Use this to put a note about how to use the template on the template page itself. Example:

Say what the template is for, and show how to put it on a page 
(typically we show wiki markup in <pre> tags so that it looks 
like an example and doesn't get parsed).

{{Name of template here}}


Text between includeonly tags on a template will only be transcludeded--it will not show on the Template page itself. If you want all pages with the template on it to be listed in a particular categories (but you don't want the Template page listed in the category) then put a category tag in your Template within includeonly tags.

[[category:short articles]]

A basic template that uses noinclude and includeonly tags is Template:Reference needed. Click on its Edit tab and have a look!

Complex templates[edit]

Templates can be extremely complex, allowing the use of many variables and "sub" templates. If you really want to know about them try here at meta Wikimedia. The majority of the situations where a complicated and multilayered template may be needed (such as those that make up the mainpage), templates are already in existence.


Sometimes a template that has been recently edited does not display as expected because MediaWiki's cache still contains the old version of the template. If you are experiencing this, purge the page to force MediaWiki to refresh its cache for that page.

A simple way to "purge" a MediaWiki page you are viewing in your browser is:

click its "View history" tab, then in your browser's location field delete just the word "history" off the end of the URL, type "purge" there (after the "=") on the end of the URL, and hit return.

This refreshes MediaWiki's cache for all templates used on that page.

See also[edit]