Open main menu

Changes

m
replace template name in first sentence, it is shown in numbered list below
{{Documentation subpage}}
<!-- Please place categories where indicated at the bottom of this page and interwikis at Wikidata (see [[Wikipedia:Wikidata]]) -->

This is one of three templates used to automatically add conversions of height measurements displayed by [[Template:Infobox person]] and other [[:Category:Infobox templates|infoboxes]] with a {{para|height}} parameter.
# [[Template:Infobox person/height]] changes text for units of height to the abbreviations "m", "cm", "ft", or "in", then passes the string to:
# [[Template:Infobox person/height/locate]] which replaces any instances of <code>&amp;nbsp;</code> with a space, and determines the positions of "m", "cm", "ft", or "in" within that string, all of which is passed to:
# [[Template:Infobox person/height/switch]] which does the conversion

== Usage ==

* <code><nowiki>{{Template:Infobox person/height/locate|1.57 m}}</nowiki></code> &rarr; {{Template:Infobox person/height/locate|1.57 m}}
* <code><nowiki>{{Template:Infobox person/height/locate|1.57&amp;nbsp;m}}</nowiki></code> &rarr; {{Template:Infobox person/height/locate|1.57&nbsp;m}}
* <code><nowiki>{{Template:Infobox person/height/locate|157 cm}}</nowiki></code> &rarr; {{Template:Infobox person/height/locate|157 cm}}
* <code><nowiki>{{Template:Infobox person/height/locate|157&amp;nbsp;cm}}</nowiki></code> &rarr; {{Template:Infobox person/height/locate|157&nbsp;cm}}
* <code><nowiki>{{Template:Infobox person/height/locate|5 ft}}</nowiki></code> &rarr; {{Template:Infobox person/height/locate|5 ft}}
* <code><nowiki>{{Template:Infobox person/height/locate|5&amp;nbsp;ft}}</nowiki></code> &rarr; {{Template:Infobox person/height/locate|5&nbsp;ft}}
* <code><nowiki>{{Template:Infobox person/height/locate|2 in}}</nowiki></code> &rarr; {{Template:Infobox person/height/locate|2 in}}
* <code><nowiki>{{Template:Infobox person/height/locate|2&amp;nbsp;in}}</nowiki></code> &rarr; {{Template:Infobox person/height/locate|2&nbsp;in}}
* <code><nowiki>{{Template:Infobox person/height/locate|5 ft 2 in}}</nowiki></code> &rarr; {{Template:Infobox person/height/locate|5 ft 2 in}}
* <code><nowiki>{{Template:Infobox person/height/locate|5&amp;nbsp;ft 2&amp;nbsp;in}}</nowiki></code> &rarr; {{Template:Infobox person/height/locate|5&nbsp;ft 2&nbsp;in}}
* <code><nowiki>{{Template:Infobox person/height/locate|5&amp;nbsp;ft 2&amp;nbsp;in (2012)}}</nowiki></code> &rarr; {{Template:Infobox person/height/locate|5&nbsp;ft 2&nbsp;in (2012)}}
* <code><nowiki>{{Template:Infobox person/height/locate|5&amp;nbsp;ft 2&amp;nbsp;in (2012)<ref>citation goes here</ref>}}</nowiki></code> &rarr; {{Template:Infobox person/height/locate|5&nbsp;ft 2&nbsp;in (2012)<ref>citation goes here</ref>}}

<references />

== Exceptions ==

Does not replace numbers in hard-coded conversions (examples intentionally show incorrect conversions):
* <code><nowiki>{{Template:Infobox person/height/locate|5 ft 2 in (100 cm)}}</nowiki></code> &rarr; {{Template:Infobox person/height/locate|5 ft 2 in (100 cm)}}
* <code><nowiki>{{Template:Infobox person/height/locate|157 cm (5 ft 5 in)}}</nowiki></code> &rarr; {{Template:Infobox person/height/locate|157 cm (5 ft 5 in)}}

Does not replace numeric output of conversion templates such as {{tl|convert}} or {{tl|height}} (examples have precision different than usual):

* <code><nowiki>{{Template:Infobox person/height/locate|{{convert|5|ft|2|in|m|3|abbr=on}}}}</nowiki></code> &rarr; {{Template:Infobox person/height/locate|{{convert|5|ft|2|in|m|3|abbr=on}}}}
* <code><nowiki>{{Template:Infobox person/height/locate|{{convert|1.57|m|ftin|1|abbr=on}}}}</nowiki></code> &rarr; {{Template:Infobox person/height/locate|{{convert|1.57|m|ftin|1|abbr=on}}}}
* <code><nowiki>{{Template:Infobox person/height/locate|{{height|ft=5|in=2|precision=3|abbr=yes}}}}</nowiki></code> &rarr; {{Template:Infobox person/height/locate|{{height|ft=5|in=2|precision=3|abbr=yes}}}}
* <code><nowiki>{{Template:Infobox person/height/locate|{{height|m=1.57|frac=16|abbr=yes}}}}</nowiki></code> &rarr; {{Template:Infobox person/height/locate|{{height|m=1.57|frac=16|abbr=yes}}}}

== Technical details ==

The following examples show how the template works:

=== ft & in ===
<pre>
{{Infobox person/height/switch
|{{{1|5 ft 2&amp;nbsp;in}}}
|{{#invoke:String|replace|{{{1|5 ft 2&amp;nbsp;in}}}|&amp;nbsp;| }}
|m={{#invoke:String|find|{{#invoke:String|replace|{{{1|5 ft 2&amp;nbsp;in}}}|&amp;nbsp;| }}|m}}
|c={{#invoke:String|find|{{#invoke:String|replace|{{{1|5 ft 2&amp;nbsp;in}}}|&amp;nbsp;| }}|cm}}
|f={{#invoke:String|find|{{#invoke:String|replace|{{{1|5 ft 2&amp;nbsp;in}}}|&amp;nbsp;| }}|ft}}
|i={{#invoke:String|find|{{#invoke:String|replace|{{{1|5 ft 2&amp;nbsp;in}}}|&amp;nbsp;| }}|in}}
}}
</pre>

Result:<br /><code>
<nowiki>{{Infobox person/height/switch</nowiki>
<nowiki> |</nowiki>{{{1|5 ft 2&amp;nbsp;in}}}
<nowiki> |</nowiki>{{#invoke:String|replace|{{{1|5 ft 2&nbsp;in}}}|&nbsp;| }}
<nowiki> |m=</nowiki>{{#invoke:String|find|{{#invoke:String|replace|{{{1|5 ft 2&nbsp;in}}}|&nbsp;| }}|m}}
<nowiki> |c=</nowiki>{{#invoke:String|find|{{#invoke:String|replace|{{{1|5 ft 2&nbsp;in}}}|&nbsp;| }}|cm}}
<nowiki> |f=</nowiki>{{#invoke:String|find|{{#invoke:String|replace|{{{1|5 ft 2&nbsp;in}}}|&nbsp;| }}|ft}}
<nowiki> |i=</nowiki>{{#invoke:String|find|{{#invoke:String|replace|{{{1|5 ft 2&nbsp;in}}}|&nbsp;| }}|in}}
<nowiki>}}</nowiki>
</code>

=== cm ===
<pre>
{{Infobox person/height/switch
|{{{1|198&amp;nbsp;cm}}}
|{{#invoke:String|replace|{{{1|198&amp;nbsp;cm}}}|&amp;nbsp;| }}
|m={{#invoke:String|find|{{#invoke:String|replace|{{{1|198&amp;nbsp;cm}}}|&amp;nbsp;| }}|m}}
|c={{#invoke:String|find|{{#invoke:String|replace|{{{1|198&amp;nbsp;cm}}}|&amp;nbsp;| }}|cm}}
|f={{#invoke:String|find|{{#invoke:String|replace|{{{1|198&amp;nbsp;cm}}}|&amp;nbsp;| }}|ft}}
|i={{#invoke:String|find|{{#invoke:String|replace|{{{1|198&amp;nbsp;cm}}}|&amp;nbsp;| }}|in}}
}}
</pre>

Result:<br /><code>
<nowiki>{{Infobox person/height/switch</nowiki>
<nowiki> |</nowiki>{{{1|198&amp;nbsp;cm}}}
<nowiki> |</nowiki>{{#invoke:String|replace|{{{1|198&nbsp;cm}}}|&nbsp;| }}
<nowiki> |m=</nowiki>{{#invoke:String|find|{{#invoke:String|replace|{{{1|198&nbsp;cm}}}|&nbsp;| }}|m}}
<nowiki> |c=</nowiki>{{#invoke:String|find|{{#invoke:String|replace|{{{1|198&nbsp;cm}}}|&nbsp;| }}|cm}}
<nowiki> |f=</nowiki>{{#invoke:String|find|{{#invoke:String|replace|{{{1|198&nbsp;cm}}}|&nbsp;| }}|ft}}
<nowiki> |i=</nowiki>{{#invoke:String|find|{{#invoke:String|replace|{{{1|198&nbsp;cm}}}|&nbsp;| }}|in}}
<nowiki>}}</nowiki>
</code>

=== m ===
<pre>
{{Infobox person/height/switch
|{{{1|1.98&amp;nbsp;m}}}
|{{#invoke:String|replace|{{{1|1.98&amp;nbsp;m}}}|&amp;nbsp;| }}
|m={{#invoke:String|find|{{#invoke:String|replace|{{{1|1.98&amp;nbsp;m}}}|&amp;nbsp;| }}|m}}
|c={{#invoke:String|find|{{#invoke:String|replace|{{{1|1.98&amp;nbsp;m}}}|&amp;nbsp;| }}|cm}}
|f={{#invoke:String|find|{{#invoke:String|replace|{{{1|1.98&amp;nbsp;m}}}|&amp;nbsp;| }}|ft}}
|i={{#invoke:String|find|{{#invoke:String|replace|{{{1|1.98&amp;nbsp;m}}}|&amp;nbsp;| }}|in}}
}}
</pre>

Result:<br /><code>
<nowiki>{{Infobox person/height/switch</nowiki>
<nowiki> |</nowiki>{{{1|1.98&amp;nbsp;m}}}
<nowiki> |</nowiki>{{#invoke:String|replace|{{{1|1.98&nbsp;m}}}|&nbsp;| }}
<nowiki> |m=</nowiki>{{#invoke:String|find|{{#invoke:String|replace|{{{1|1.98&nbsp;m}}}|&nbsp;| }}|m}}
<nowiki> |c=</nowiki>{{#invoke:String|find|{{#invoke:String|replace|{{{1|1.98&nbsp;m}}}|&nbsp;| }}|cm}}
<nowiki> |f=</nowiki>{{#invoke:String|find|{{#invoke:String|replace|{{{1|1.98&nbsp;m}}}|&nbsp;| }}|ft}}
<nowiki> |i=</nowiki>{{#invoke:String|find|{{#invoke:String|replace|{{{1|1.98&nbsp;m}}}|&nbsp;| }}|in}}
<nowiki>}}</nowiki>
</code>

== See also ==
* [[Template:Infobox person]]
* [[Template:Infobox person/weight]]
** [[Template:Infobox person/weight/locate]]
** [[Template:Infobox person/weight/switch]]
* [[Template:Infobox person/length]]
** [[Template:Infobox person/length/locate]]
** [[Template:Infobox person/length/switch]]

<includeonly>{{#ifeq:{{SUBPAGENAME}}|sandbox | |
<!-- Categories below this line, please; interwikis at Wikidata -->
[[Category:Template implementation details]]

}}</includeonly>
Anonymous user