2013 Convention Preview: Virginia's GOP delegates to choose nominees for lt. gov and AG this weekend!
Help:Using templates
Contents |
What does a template look like?
When browsing a page, you might not know it has templates, but if you see the same navigation box on pages that share a topic, that might be a template in use.
You will know a template is in use for certain if try to edit it or "view source" (on locked articles or pages).
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 "}" (usually SHIFT-[ or SHIFT-]).
So, you might see something like:
{{Maine ballot years}}
Templates have a variety of uses, but at Ballotpedia they typically are used to categorize articles, create infoboxes (like candidate information), create links, make lists, add navigation banners (at the top or bottom of articles), or add navigation boxes (usually floating near the top-right of the article.
Basic instructions
A template is simply a page (usually a very brief one) that is inserted into another page.
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 its 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).
- Parameters names given as numbers ("1", "2", etc.) are expected to have their values come in the order of their number.
- 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.
Example of a template with parameters used
Let's take the {{welcome}} template and try some wikicode examples.
- Welcome using only 1st parameter (username)
{{welcome|ConcernedCitizen}}
- Output
- Notice the customized greeting: "Hello, ConcernedCitizen,...".
We're glad you're here. Here's how to get started: 1. Take Ballotpedia's 5-minute tutorial.
3. Find an article you'd like to improve. You can also sign up for a webinar on how to edit, or just contact us. Welcome to our community! --Bailey Ludlam, Ballotpedia's managing editor |
- Welcome using 1st parameter (username) and sig=
{{welcome|ConcernedCitizen|sig=Leslie Graves}}
As you see in the examples about, a pipe character ( | ) is used to separate the template name "welcome" from parameters that follow and the parameters are also separated by pipe characters.
- Output
- Notice this version is the same as above except for "Leslie Graves" added as a signature at the bottom.
We're glad you're here. Here's how to get started: 1. Take Ballotpedia's 5-minute tutorial.
3. Find an article you'd like to improve. You can also sign up for a webinar on how to edit, or just contact us. Welcome to our community! --Bailey Ludlam, Ballotpedia's managing editor
|
Of course, the {{welcome}} template doesn't require any parameters, so it could be used that way also.
- Welcome using no parameters
{{welcome}}
- Output with no parameters
- Notice the strange greeting: "Hello, Using templates,...."This is because it uses the current page as the user name, even though this is not a user page.
We're glad you're here. Here's how to get started: 1. Take Ballotpedia's 5-minute tutorial.
3. Find an article you'd like to improve. You can also sign up for a webinar on how to edit, or just contact us. Welcome to our community! --Bailey Ludlam, Ballotpedia's managing editor |
