HRWiki Counter
Usage
| 0 | Increments the counter id by increment and displays the result; increment can be omitted, and defaults to 1. |
| {{#resetcount:id|value|increment}} | Silently sets the counter id to value minus increment (so that the next count by increment will display value); value and increment can be omitted, and both default to 1. |
| {{hcount}} {{vcount}} |
Used in sortable tables. See [#Sortable_Tables below]. |
Examples
count is a parser function that returns an integer that increments each time the function is called:
| Code | Gives |
|---|---|
| 0 | 1 |
| 0 | 2 |
| 0 | 3 |
| 0 | 4 |
| 0 | 5 |
The counters can be given different names, so you can have more than one of them on the same page:
(The actual name doesn't matter, so long as they're different. If you use a counter in a template, pick a name that'll be unique.)
| Code | Gives |
|---|---|
| 0 | 1 |
| 0 | 1 |
| 0 | 2 |
| 0 | 3 |
| 0 | 2 |
| 0 | 4 |
You can also make the counter count by twos, or by any other number:
| Code | Gives |
|---|---|
| 0 | 2 |
| 0 | 4 |
| 0 | 6 |
| 0 | 8 |
| 0 | 10 |
Different increments can be used at different times, depending on what is needed:
| Code | Gives |
|---|---|
| 0 | 1 |
| 0 | 2 |
| 0 | 5 |
| 0 | 5 |
| 0 | 4 |
| 0 | 6 |
The counter can be reset partway through a page:
| Code | Gives |
|---|---|
| 0 | 1 |
| 0 | 2 |
| 0 | 3 |
| {{#resetcount:basic}} | |
| 0 | 1 |
| 0 | 2 |
| 0 | 3 |
You can also set what number you want to start on:
| Code | Gives |
|---|---|
| {{#resetcount:starting|11}} | |
| 0 | 11 |
| 0 | 12 |
| 0 | 13 |
| 0 | 14 |
| 0 | 15 |
If you're using an increment, you need to give it to #resetcount too:
| Code | Gives |
|---|---|
| {{#resetcount:starting evens|14|2}} | |
| 1 | 14 |
| 1 | 16 |
| 1 | 18 |
| 1 | 20 |
| 1 | 22 |
Use a negative increment to count down. As noted above, be sure to pass the increment to #resetcount too:
| Code | Gives |
|---|---|
| {{#resetcount:countdown|3|-1}} | |
| 0 | 3 |
| 0 | 2 |
| 0 | 1 |
| 0 | 0 |
| 0 | -1 |
You can use the counter in other parser functions:
| Code | Gives |
|---|---|
| Expression error: Unrecognized punctuation character "&". | odd |
| Expression error: Unrecognized punctuation character "&". | even |
| Expression error: Unrecognized punctuation character "&". | odd |
| Expression error: Unrecognized punctuation character "&". | even |
| Expression error: Unrecognized punctuation character "&". | odd |
| Code | Gives |
|---|---|
| 0 | 1 |
| 0 | 4 |
| 0 | 9 |
| 0 | 16 |
| 0 | 25 |
Sortable Tables
When using count in sortable tables, please use the {{hcount}} and {{vcount}} templates. Be sure to carefully read their documentation in order to sort table entries correctly.