Difference between revisions of "Template:Infobox person/weight/locate/sandbox"
imported>Zyxw (add option to output stlb which can be invoked from an infobox template) |
imported>Zyxw (allow separate options for kg-stlb and lb-stlb) |
||
Line 5: | Line 5: | ||
|s={{#invoke:String|find|{{#invoke:String|replace|{{{1|}}}| | }}|st}} | |s={{#invoke:String|find|{{#invoke:String|replace|{{{1|}}}| | }}|st}} | ||
|l={{#invoke:String|find|{{#invoke:String|replace|{{{1|}}}| | }}|lb}} | |l={{#invoke:String|find|{{#invoke:String|replace|{{{1|}}}| | }}|lb}} | ||
− | |stlb={{#if:{{{stlb|}}}|{{{stlb}}}}} | + | |kg-stlb={{#if:{{{kg-stlb|}}}|{{{kg-stlb}}}}} |
+ | |lb-stlb={{#if:{{{lb-stlb|}}}|{{{lb-stlb}}}}} | ||
}}<noinclude> | }}<noinclude> | ||
{{Documentation}} | {{Documentation}} | ||
</noinclude> | </noinclude> |
Latest revision as of 00:50, 13 August 2017
![]() | This is the template sandbox page for Template:Infobox person/weight/locate (diff). |
This is one of three templates used to automatically add conversions of weight measurements displayed by Template:Infobox person and other infoboxes with a |weight=
parameter.
- Template:Infobox person/weight changes text for units of weight to the abbreviations "kg", "lb", or "st", then passes the string to:
- Template:Infobox person/weight/locate which replaces any instances of
with a space, and determines the positions of "kg", "lb", or "st" within that string, all of which is passed to: - Template:Infobox person/weight/switch which does the conversion
Usage
{{Template:Infobox person/weight/locate|108 kg}}
→ 108 kg (238 lb){{Template:Infobox person/weight/locate|108 kg}}
→ 108 kg (238 lb){{Template:Infobox person/weight/locate|238 lb}}
→ 238 lb (108 kg){{Template:Infobox person/weight/locate|238 lb}}
→ 238 lb (108 kg){{Template:Infobox person/weight/locate|17 st}}
→ 17 st (238 lb; 108 kg){{Template:Infobox person/weight/locate|17 st}}
→ 17 st (238 lb; 108 kg){{Template:Infobox person/weight/locate|108 kg (2012)}}
→ 108 kg (238 lb) (2012){{Template:Infobox person/weight/locate|108 kg (2012)<ref>citation goes here</ref>}}
→ 108 kg (238 lb) (2012)[1]
- ↑ citation goes here
Exceptions
Does not replace numbers in hard-coded conversions (examples intentionally show incorrect conversions):
{{Template:Infobox person/weight/locate|108 kg (229 lb)}}
→ 108 kg (229 lb){{Template:Infobox person/weight/locate|238 lb (119 kg)}}
→ 238 lb (119 kg){{Template:Infobox person/weight/locate|17 st (229 lb; 119 kg)}}
→ 17 st (229 lb; 119 kg)
Does not replace numeric output of conversion templates such as {{convert}} (examples have precision different than usual):
{{Template:Infobox person/weight/locate|{{convert|108|kg|lb|1|abbr=on}}}}
→ 108 kg (238.1 lb){{Template:Infobox person/weight/locate|{{convert|238|lb|kg|2|abbr=on}}}}
→ 238 lb (107.95 kg){{Template:Infobox person/weight/locate|{{convert|17|st|3|abbr=on}}}}
→ 17 st (238.000 lb; 107.955 kg)
Technical details
The following examples show how the template works:
kg
{{Infobox person/weight/switch |108 kg |{{#invoke:String|replace|108 kg| | }} |k={{#invoke:String|find|{{#invoke:String|replace|108 kg| | }}|kg}} |s={{#invoke:String|find|{{#invoke:String|replace|108 kg| | }}|st}} |l={{#invoke:String|find|{{#invoke:String|replace|108 kg| | }}|lb}} }}
Result:
{{Infobox person/weight/switch
|108 kg
|108 kg
|k=5
|s=0
|l=0
}}
lb
{{Infobox person/weight/switch |238 lb |{{#invoke:String|replace|238 lb| | }} |k={{#invoke:String|find|{{#invoke:String|replace|238 lb| | }}|kg}} |s={{#invoke:String|find|{{#invoke:String|replace|238 lb| | }}|st}} |l={{#invoke:String|find|{{#invoke:String|replace|238 lb| | }}|lb}} }}
Result:
{{Infobox person/weight/switch
|238 lb
|238 lb
|k=0
|s=0
|l=5
}}
st
{{Infobox person/weight/switch |17 st |{{#invoke:String|replace|17 st| | }} |k={{#invoke:String|find|{{#invoke:String|replace|17 st| | }}|kg}} |s={{#invoke:String|find|{{#invoke:String|replace|17 st| | }}|st}} |l={{#invoke:String|find|{{#invoke:String|replace|17 st| | }}|lb}} }}
Result:
{{Infobox person/weight/switch
|17 st
|17 st
|k=0
|s=4
|l=0
}}
st/lb
{{Infobox person/weight/switch |17 st 7 lb |{{#invoke:String|replace|17 st 7 lb| | }} |k={{#invoke:String|find|{{#invoke:String|replace|17 st 7 lb| | }}|kg}} |s={{#invoke:String|find|{{#invoke:String|replace|17 st 7 lb| | }}|st}} |l={{#invoke:String|find|{{#invoke:String|replace|17 st 7 lb| | }}|lb}} }}
Result:
{{Infobox person/weight/switch
|17 st 7 lb
|17 st 7 lb
|k=0
|s=4
|l=9
}}
See also
The above documentation is transcluded from Template:Infobox person/weight/locate/doc. (edit | history) Editors can experiment in this template's sandbox (edit | diff) and testcases (create) pages. Please add categories to the /doc subpage. Subpages of this template. |