Template:Unit: Difference between revisions

From Eco - English Wiki
[unchecked revision][checked revision]
m (Improve documentation.)
m (Add check to ensure at least one parameter.)
 
(3 intermediate revisions by the same user not shown)
Line 1: Line 1:
<includeonly>{{#invoke:Sandbox/Demian/Unit|unit}}</includeonly><noinclude>
<includeonly>{{#if:{{{1|}}} {{{2|}}}<!--
== Usage ==
-->|{{#invoke:Unit|unit}}<!--
 
-->|<span style="color:red">ERROR: No value given to Unit template!</span>|}}</includeonly><noinclude>
{{tlx|Template Sandbox/Demian/Unit|''abbr''}}
{{doc}}</noinclude>
 
== Examples ==
{| class="wikitable"
|+ Commonly used units.
|-
! Code !! Result
|-
| {{tlx|Template Sandbox/Demian/Unit|ppm}} || {{Template Sandbox/Demian/Unit|ppm}}
|-
| {{tlx|Template Sandbox/Demian/Unit|m}} || {{Template Sandbox/Demian/Unit|m}}
|-
| {{tlx|Template Sandbox/Demian/Unit|m/s}} || {{Template Sandbox/Demian/Unit|m/s}}
|-
| {{tlx|Template Sandbox/Demian/Unit|mps}} || {{Template Sandbox/Demian/Unit|mps}}
|-
| {{tlx|Template Sandbox/Demian/Unit|kg}} || {{Template Sandbox/Demian/Unit|kg}}
|-
| {{tlx|Template Sandbox/Demian/Unit|degc}} || {{Template Sandbox/Demian/Unit|degc}}
|}
 
Note that the abbreviation is case sensitive and special symbols are formatted correctly:
{| class="wikitable"
|+ Various units.
|-
! Code !! Result
|-
| {{tlx|Template Sandbox/Demian/Unit|mHz}} || {{Template Sandbox/Demian/Unit|mHz}}
|-
| {{tlx|Template Sandbox/Demian/Unit|MHz}} || {{Template Sandbox/Demian/Unit|MHz}}
|-
| {{tlx|Template Sandbox/Demian/Unit|m2}} || {{Template Sandbox/Demian/Unit|m2}}
|-
| {{tlx|Template Sandbox/Demian/Unit|kohm}} || {{Template Sandbox/Demian/Unit|kohm}}
|-
| {{tlx|Template Sandbox/Demian/Unit|kWh}} || {{Template Sandbox/Demian/Unit|kWh}}
|-
| {{tlx|Template Sandbox/Demian/Unit|um}} || {{Template Sandbox/Demian/Unit|um}}
|-
| {{tlx|Template Sandbox/Demian/Unit|J/(Kmol)}} || {{Template Sandbox/Demian/Unit|J/(Kmol)}}
|}
 
If a unit definition is not found, the abbreviation (or text) is returned unchanged.
{| class="wikitable"
|+ Invalid units.
|-
! Code !! Result
|-
| {{tlx|Template Sandbox/Demian/Unit|things}} || {{Template Sandbox/Demian/Unit|things}}
|-
| {{tlx|Template Sandbox/Demian/Unit|something/other}} || {{Template Sandbox/Demian/Unit|something/other}}
|-
| {{tlx|Template Sandbox/Demian/Unit|players per hour}} || {{Template Sandbox/Demian/Unit|players per hour}}
|}
 
== Modules ==
 
This template is using the following Modules:
*[[Module:Sandbox/Demian/Unit]]
 
== Documentation ==
<templatedata>
{
"params": {
"abbr": {
"label": "Unit abbreviation",
"description": "Case sensitive abbreviation of a unit of measure. If the abbreviation contains a forward slash \"/\" it may be replaced with the character \"p\".",
"example": "m/s, mps, GHz, ppm, kg, m2, kWh",
"type": "string",
"required": true
}
},
"description": "Adds a tooltip to an abbreviation of a unit of measure showing the actual name of the unit.",
"format": "inline",
"paramOrder": [
"abbr"
]
}
</templatedata></noinclude>

Latest revision as of 15:22, 27 February 2022

Template:Doc/start

Add a tooltip to an abbreviation of a unit of measure showing the actual name of the unit.

Template parameters[Edit template data]

This template prefers inline formatting of parameters.

ParameterDescriptionTypeStatus
Numbernumber

Numerical value to format for display with the unit.

Example
2, -2, 3.45
Numberoptional
Unit abbreviationabbr

Case sensitive abbreviation of a unit of measure. If the abbreviation contains a forward slash "/" it may be replaced with the character "p".

Example
m/s, mps, GHz, ppm, kg, m2, kWh
Stringoptional

Usage[edit source]

  • With a formatted number: {{Unit|number|abbr}}
    • If a number is specified, it is formatted with a space " " as a thousands separator and a period "." as the decimal separator.
  • With unit abbreviation only: {{Unit|abbr}}

New units[edit source]

Recognized units are defined and documented in Module:Unit/data.

Examples[edit source]

Commonly used units.
Code Result
{{Unit|ppm}} Script error: No such module "Unit".
{{Unit|1200|m}} Script error: No such module "Unit".
{{Unit|1|m/s}} Script error: No such module "Unit".
{{Unit|mps}} Script error: No such module "Unit".
34 {{Unit|kg}} 34 Script error: No such module "Unit".
{{Unit|+2|degc}} Script error: No such module "Unit".

Note that the abbreviation is case sensitive and if the unit contains special symbols they are displayed correctly:

Various units.
Code Result
{{Unit|-2,1|mHz}} Script error: No such module "Unit".
{{Unit|-0.1|MHz}} Script error: No such module "Unit".
{{Unit|0|m2}} Script error: No such module "Unit".
{{Unit|+1|kohm}} Script error: No such module "Unit".
{{Unit|852001,99|kWh}} Script error: No such module "Unit".
4–8 {{Unit|um}} 4–8 Script error: No such module "Unit".
{{Unit|J/(Kmol)}} Script error: No such module "Unit".

If a unit definition is not found, the abbreviation (or text) is returned unchanged. However, if the unit definition data is later updated to include the unit, it will begin using the tooltip correctly later.

Invalid units.
Code Result
{{Unit|99|things}} Script error: No such module "Unit".
{{Unit|something/other}} Script error: No such module "Unit".
{{Unit|-2|players per hour}} Script error: No such module "Unit".
{{Unit|7|lbft}} of torque Script error: No such module "Unit". of torque
{{Unit}} ERROR: No value given to Unit template!

Modules[edit source]

This template is using the following Modules:

Template:Doc/end