Community Central
Community Central

Templates allow you to pass parameters. These are used to alter the way the template is displayed, such as including specific text or altering the design.

Note: this page describes manipulating templates in source editor. When inserting templates on pages, the VisualEditor can allow you to define and insert parameter text without touching wikitext.

Simple parameters[]

For small templates, using basic, unnamed parameters will often suffice. These parameters are numbered rather than named, using {{{1}}}, {{{2}}}, {{{3}}}, and so on.


This guide will walk through creating a basic box template with simple parameters:

  • Create a page on your wiki with a basic name (for instance, "Template:Box"):
  • Add the following code to that page:
<div style="background-color: #DDD2; border: 1px solid #5556; padding-top: 2em; text-align: center; width: 10em;">
  • Save the page to see that it displays the following content:
  • Create an article page on your wiki called Template test
  • Enter the following code on that page to display your template:
{{Box|Example text}}
  • Save the page and note that it displays the following content:
Example text

Understanding what happened[]

This replacement happened because {{{1}}} tells the wiki to pass the first parameter of the template here. This can be extended with {{{2}}}, {{{3}}}, etc.

The number represents the number of the parameter:

{{box|first parameter|second parameter|third parameter}}

Named and default parameters[]

For more complex templates, it is often better to use named parameters. This allows for more freedom in how templates are created, and also makes templates easier to use as users will know which parameter affects which element.


This guide will walk through using named parameters to the above "Template:Box" example:

  • Using the same example pages as before, edit "Template:Box" and replace the content with the following code:
<div style="background-color: {{{bgcolor|#DDD2}}}; border: 1px solid #5556; padding: 2em; text-align: center; width: 10em;">
{{{text}}} introduces the concept of a named parameter. {{{bgcolor|#DDD2}}} also introduces the concept of a default parameter: if "bgcolor" is not defined, "#DDD2" will be used.
  • Edit the page "Template test" and replace it with the following code:
{{box|bgcolor=navy|text=A navy blue box}}
  • Save your page, and note that it displays the following:
A navy blue box

Understanding what happened[]

As the parameters have names, you can pass them in any order, so {{box|text=A navy blue box|bgcolor=navy}} would produce an identical box.

Due to default parameters, if, say, the background color was not defined - as in {{box|text=A navy blue box}} - you would get:

A navy blue box

Named parameters are frequently written on separate lines or with space between parameter name and "=" sign, to aid readability. Generally, this is done in a big template composed of many parameters. It is not unusual to see them written in this form:

| bgcolor= navy
| text= A navy blue box

A default parameter can be left blank if you do not want an optional parameter to insert anything on a page.

For example, if you wrote {{{text}}} in a template, but did not include a "text=" input on the article page, it would show up as "{{{text}}}". However, if you wrote {{{text|}}} in the template, the default is no text, so nothing would show up on the article page.

It is also possible to set another parameter as the default of a parameter, like {{{text|{{{1|}}}}}}. This way, if an editor uses {{box|Example text}}, they will get the same output as {{box|text=Example text}}. This means that a template will default to the |text= parameter, but if it cannot find |text= , it will use the unnamed parameter instead; if it cannot find {{{1}}}, it will use no text.

Skipping a parameter[]

In some templates there may be parameters that are optional - may be supplied or not supplied.

When creating such a template, it is recommended to either use a named parameter for the optional one or to make it the last one so that users can just not supply it. If it is not named and not the last one, there is no easy way to skip it. A user can supply an empty value like

{{box|first parameter||third parameter}}

but this may not work as intended, depending on the template, because empty values behave different than non-supplied values. For example, default values are not used because the parameter has been supplied, just with an empty value.

If a template uses optional unnamed parameters and it is necessary to skip an unnamed parameter, it is possible by using explicit numbers for all parameters, like

{{box|1=first parameter|3=third parameter}}

Another alternative is that the template will check specifically for empty parameters by using conditional Parser functions.

Next steps[]

Now that you learned what template parameters are, you should learn how to use Parser functions.

You should also learn how to document the template's parameters.

See also[]