Difference between revisions of "Template:Infobox person/length/switch"

From blackwiki
Jump to navigation Jump to search
imported>Primefac
m (Changed protection level for "Template:Infobox person/length/switch": high-risk template with 4000+ transclusions ([Edit=Require template editor access] (indefinite) [Move=Require template editor access] (indefinite)))
imported>Zyxw
(Add conversion for metres so "1.98 m" will output "1.98 m (78 in)". Check for existing conversion to metres so "78 in (1.91 m)" will not output "78 in (198 cm) (1.91 m)". Tested first with /sandbox and /testcases.)
 
Line 1: Line 1:
 
{{#switch:0
 
{{#switch:0
  |{{{c}}}{{{i}}}={{{1|}}}
+
    |{{{c}}}{{{m}}}{{{i}}}={{{1|}}}
  |{{{i}}}={{#iferror:{{#expr:{{#invoke:String|sub|{{{2|0}}}|1|{{#expr:{{{c|1}}}-1}}}}}}
+
    |{{{i}}}={{#ifeq:{{{c}}}|0
        |{{{1|}}}
+
        |{{#iferror:{{#expr:{{#invoke:String|sub|{{{2|0}}}|1|{{#expr:{{{m|1}}}-1}}}}}}
        |{{convert|{{#invoke:String|sub|{{{2|0}}}|1|{{#expr:{{{c|1}}}-1}}}}|cm|in|0|abbr=on}}{{#invoke:String|sub|{{{2|0}}}|{{#expr:{{{c|1}}}+2}}}}
+
            |{{{1|}}}
      }}
+
            |{{convert|{{#invoke:String|sub|{{{2|0}}}|1|{{#expr:{{{m|1}}}-1}}}}|m|in|0|abbr=on}}{{#invoke:String|sub|{{{2|0}}}|{{#expr:{{{m|1}}}+1}}}}
  |{{{c}}}={{#iferror:{{#expr:{{#invoke:String|sub|{{{2|0}}}|1|{{#expr:{{{i|1}}}-1}}}}}}
+
            }}
 +
        |{{#iferror:{{#expr:{{#invoke:String|sub|{{{2|0}}}|1|{{#expr:{{{c|1}}}-1}}}}}}
 +
            |{{{1|}}}
 +
            |{{convert|{{#invoke:String|sub|{{{2|0}}}|1|{{#expr:{{{c|1}}}-1}}}}|cm|in|0|abbr=on}}{{#invoke:String|sub|{{{2|0}}}|{{#expr:{{{c|1}}}+2}}}}
 +
            }}
 +
        }}
 +
    |{{{c}}}{{{m}}}={{#iferror:{{#expr:{{#invoke:String|sub|{{{2|0}}}|1|{{#expr:{{{i|1}}}-1}}}}}}
 
         |{{{1|}}}
 
         |{{{1|}}}
 
         |{{convert|{{#invoke:String|sub|{{{2|0}}}|1|{{#expr:{{{i|1}}}-1}}}}|in|cm|0|abbr=on}}{{#invoke:String|sub|{{{2|0}}}|{{#expr:{{{i|1}}}+2}}}}
 
         |{{convert|{{#invoke:String|sub|{{{2|0}}}|1|{{#expr:{{{i|1}}}-1}}}}|in|cm|0|abbr=on}}{{#invoke:String|sub|{{{2|0}}}|{{#expr:{{{i|1}}}+2}}}}
      }}
+
        }}
  |{{{1|}}}
+
    |{{{1|}}}
 
}}<noinclude>
 
}}<noinclude>
 
{{Documentation}}
 
{{Documentation}}
 
</noinclude>
 
</noinclude>

Latest revision as of 08:33, 12 July 2018

Template documentation[view] [edit] [history] [purge]

This is one of three templates used to automatically add conversions of length measurements displayed by infoboxes, such as the |reach= parameter in {{Infobox boxer}} or the |spike= and |block= parameters in {{Infobox volleyball biography}}.

  1. Template:Infobox person/length changes text for units of length to the abbreviations "in", "cm" or "m", then passes the string to:
  2. Template:Infobox person/length/locate which replaces any instances of &nbsp; with a space, and determines the positions of "in", "cm" or "m" within that string, all of which is passed to:
  3. Template:Infobox person/length/switch which does the conversion

See also