Help:Template parameters

Templates allow you to pass parameters that can be used to affect the content or design of the template.

Note: when inserting templates on pages, the visual editors can allow you to define and insert parameter text without touching wikitext.

Simple parameters

 * Create a page on your wiki called "Template:Box":
 * Add the following code to that page:




 * Save the page and note 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
As an alternative to the above, you can use named parameters. Though this makes the code slightly more complex, it allows more freedom in how templates are created.


 * 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, '#CDF' 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, and in some case, have 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 'text=' 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.