Help:Template parameters

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 parameters without specific names to alter a template will often suffice. These parameters are numbered rather than named, using,  ,  , etc.

Guide
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:




 * Save the page to see that it displays the following content:
 * 


 * Create an article page on your wiki called
 * Enter the following code on that page to display your template:


 * Save the page and note that it displays the following content:
 * Example text

Understanding what happened
This replacement happened because  tells the wiki to pass the first parameter of the template here. This can be extended with,  , etc.

The number represents the number of the parameter:

If you wish not to use a certain parameter, you can leave it blank, but the " " character must still be included. For example:

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.

Guide
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:




 * introduces the concept of a named parameter.  also introduces the concept of a default parameter: if "bgcolor" is not defined, " " will be used.


 * Edit the page "Template test" and replace it with the following code:


 * 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  would produce an identical box.

Due to default parameters, if, say, the background color was not defined - as in  - 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 composing of many parameters. It is not unusual to see them written in this form:

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

For example, if you wrote  in a template, but did not include a " " input on the article page, it would show up as "". However, if you wrote  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. This way, if an editor uses, they will get the same output as. This means that a template will default to the  parameter, but if it cannot find it, it will use the unnamed parameter instead; if it cannot find that, it will use no text.