Template:Weightkey/doc

From Discworld MUD Wiki
Jump to: navigation, search

  Use this template to be able to sort on weight in a sortable table.

Provide the weight as the single parameter, without any 'lb' or other units indicator.

This template is designed to work with weights as the disc sees them (ie. in pounds and ninths of a pound), but it will accept decimals and non-ninths fractions as well if desired (though they will be internally rounded to the nearest ninth of a pound). The sort key itself is the weight in ninths of a pound, with appropriate padding to make the sorting work.

The following table illustrates various acceptable strings, and the sort keys they produce:

String Sort key
1 5/9 &&&+14
1.25 &&&+11
8/9 &&&&+8
3 &&&+27
0.5 &&&&+5
0.33 &&&&+3

When you use this template, ensure that there is the same characters or none at all after the | character before the weightkey begins. If there are spaces or something else for only some rows but not all rows it won't sort right.

For example the following have different white spaces:

 |{weightkey|1 8/9}}
 | {weightkey|1 8/9}}

Alternate printable representation

If you want what is printed to look different to what is keyed on, then use the (optional) second parameter to affect what is displayed.

Example:

{{weightkey|1 8/9|'''fish'''}}
This returns: &&&+1700 fish (but it still sorts as "1 8/9" in tables)

Another example:

{{weightkey|1 5/9|Apples}}
will key on '1 5/9' lb, and display as 'Apples'.

This may be useful if you want to apply sorting but what you want to display prevents it. Please note that you can use normal formatting with one or more ' character since those are stripped in the {{Number}} template used in this template.

Examples

{{weightkey|1 8/9}}
This returns: |&&&+1700 1 8/9
{{weightkey|'''1 8/9'''}}
This returns: &&&+1700 1 8/9
{{weightkey|1 8/9|'''fish'''}}
This returns: &&&+1700 fish (but it still sorts as "1 8/9" in tables)