Help:Using templates
From Ballotpedia
Templates are helpful pieces of code that allow you to quickly and easily add complicated pictures or text to a page on Ballotpedia.
Basic instructions
A template is simply a page (usually a very brief one) that is inserted into another page.
Templates are included on an article by typing the template's name in double curly brackets, sometimes also known as "braces". The braces or brackets key on your keyboard looks like: "{" or "}".
To add a template to an article, simply type the name of the template, surrounded by two sets of braces, as in this example:
{{Maine ballot years}}
Typing that gives you this:
| |||||||
Another example. Type {{stub}} and what you get is:
| This article is a stub. Please help Ballotpedia by expanding it. |
For simple templates, that's all there is to it.
Parameters
However, many templates allow you to add to the information in the template, or to change it's appearance, by supplying parameters.
For example, the Welcome template that someone might have put on your user talk page has one parameter--the name of the new user who is being welcomed.
"Pipe" characters (|) separate each parameter.
Parameters can be optional or required, and they can be named or not named. Two points need to be kept in mind with parameters:
- Named parameters can be supplied in any order.
- Un-named parameters must be supplied in the correct order.
Each template has (or will have) a list of parameters, looking something like this (this one is from the {{welcome}} template):
| Template Parameters (See using templates). | |||
|---|---|---|---|
| Name | Purpose | Required? | Comment |
| 1 | The user name | no (see note) | Defaults to the page name
|
| sig | The signature of the editor posting the welcome ("~~~~" will do) | no | |
This tells us the following:
- Neither parameter is required.
- The first parameter (shown as "1") is not named (hence the number, the order in which it must be supplied).
- The second parameter is named ("sig").
- If the first parameter is not supplied, then the page name is used instead.
You can assume that if no default is shown for a parameter that is not required, the result will be blank (i.e. in this case, the welcome message would not show who it was from).
You will notice that named parameters have the parameter name followed by an equals sign (=) followed by whatever you want that to be.
Parameters shown with numbers are the un-named parameters. You can treat them as named parameters, by typing 1=your text, but this is not necessary, except in the case that you want your text to include an equals sign (=).
What do you pass to parameters?
Obviously, you give a parameter the text that it expects. But in most cases, you can give a parameter any text that you like.
In some cases, however, specific text must be supplied.
In many cases you can supply a blank value to the parameter. You can set a parameter to be blank by typing nothing after the pipe character for an unnamed parameter, or nothing after the equals sign for a named parameter.
However, a well-written template will allow you to simply omit the parameter altogether, as the {{welcome}} template does with the sig parameter.

