From LifeWiki
Jump to navigation Jump to search

Templates are a commonly-used wiki tool that help provide a uniform appearance and layout for related pages. This page describes how to use templates. For a list of commonly-used templates, see LifeWiki:Template list.

Basic Usage

To use a template, you place the template's name inside double "{" brackets on a wiki page. So, to use the template Template:LinkLexicon, you would enter the following onto a wiki page:


If you try that, for example in the sandbox, what ends up being displayed on the page is:

In other words, the contents of the page Template:LinkLexicon get displayed wherever you use the template.

Most templates take parameters, which are added using the "|" symbol. Sometimes parameters are unnamed, in which case you just enter the information after the "|" symbol. For example:


This produces:

Templates that take multiple parameters generally use names to keep track of the parameters. For named parameters, you have to enter "|", the parameter's name, an "=" sign, and then the information. For example:


This produces:

The exact parameters used by any template, and what is done with those parameters, depends upon the template. The template page generally provides documentation on the possible parameters. The parameter names have to be spelled and capitalized exactly as specified, or the parameter will be completely ignored. The easiest way to start using a template is to find another page that uses that template, copy and paste it to your page, and modify the parameter values as necessary.



When you use a template on a page, the technical term for what happens is that the contents of the template get "transcluded" onto the page. This means that the template contents all appear to be copied and included into the target page. The copying process, however, is done dynamically: if the template is modified, all pages using the template are also modified. Therefore, if a decision is made to change the layout of a given template, only the template needs to be edited, instead of needing to make a change to every page that uses the template.

Transcluding can actually be done using any wiki page, not just templates. The only difference with a non-template page is that the full page name, including the namespace, has to be specified (when transcluding a template, the "Template:" part of the name is optional). Transcluding with non-templates is generally done when there is identical information that needs to be displayed on more than one page. For example, the recent news entries are transcluded because sometimes it is convenient for them to appear on the main page and sometimes it is convenient for them all to appear together on the news archive page.

Non-Included Text

Often if you look at a template's page, you will notice a lot of text that does not appear when you use the template. This is particularly common with documentation about the template. For example, the page Template:LinkLexicon shows several lines of text describing the template. But {{LinkLexicon|patternname=Glider|filename=lex_g.htm#glider}} produces the following text:

That is, none of the documentation is displayed.

This is accomplished by using the tags <noinclude> and </noinclude>. Any text placed between those two tags is only shown on the original template, and is not shown on any pages that use the template. There is also a set of <includeonly> and </includeonly> tags. In this case, any text between those tags is only shown on pages that use the template but is not visible on the template page itself.


For many templates, in particular content templates, parameters are a critical component: they provide the information that is to be formatted or otherwise displayed by the template. Parameters can also be used to provide options to the template, for example, specifying the color to be used for a box. Parameters can either be named or unnamed, depending upon how the template was designed.

For parameters used to specify options, there is generally a limited number of possible values to provide for the template. For example, if the parameter specifies a color then the value has to be a recognized color. On the other hand, parameters that provide information to be shown on a page can generally take almost any text, including links and formatting.

If a template takes unnamed parameters, they are specified by simply using the "|" symbol. Multiple unnamed parameters can be provided to a single template, in which case each parameter starts with a new "|" symbol. The order of the parameters is critical for unnamed parameters; the only way the template can tell them apart is based on the order. Internally, unnamed parameters are referenced using numbers. So {{{1}}} within a template is used to insert the contents of the first parameter.

The other way a template can be designed is to use named parameters, in which case each parameter is specified using "|name=", where name is the paramter's name. This approach is particularly common for templates that take multiple parameters, because it is easier to keep track of many parameters when each has an appropriate name. The order of named parameters does not matter. In many templates, some (or all) of the parameters are optional; optional parameters can simply be left out of the list unless needed.


There are some cases where you may want to truly insert the contents of a template into a page, instead of just transcluding the contents. Sometimes this is done to ensure that the page is not modified if the template is subsequently changed (for example, if you want to post a warning on a user's page, it is generally best to substitute the template so that the warning does not get altered).

In order to substitute a template, you simply insert the text "subst" at the start of the template. For example,


The substitution happens when you save the page (but not when you preview the page). The page looks identical to readers, but if you edit the page you will see that the template inclusion no longer exists, but instead has been replaced by the appropriate contents.

External links