Difference between revisions of "Numberswitch"
From Sega Retro
Line 1: | Line 1: | ||
− | <includeonly>{{#vardefine:testvalue|{{{number|0}}}}}{{#vardefine:highestkey|0}}{{#vardefine:output|}}{{#forargs: | + | <includeonly>{{#vardefine:testvalue|{{#replace:{{{number|0}}}|-|}}}}{{#vardefine:highestkey|0}}{{#vardefine:output|}}{{#forargs: |
| key | | key | ||
| value | | value | ||
− | | {{#ifeq:{{#var:key}}|number|| | + | | {{#vardefine:key|{{#replace:{{#var:key}}|-|}}}}{{#ifeq:{{#var:key}}|number|| |
{{#ifexpr:{{#var:key}} <= {{#var:testvalue}} and {{#var:key}}>{{#var:highestkey}}|{{#vardefine:highestkey|{{#var:key}}}} | {{#ifexpr:{{#var:key}} <= {{#var:testvalue}} and {{#var:key}}>{{#var:highestkey}}|{{#vardefine:highestkey|{{#var:key}}}} | ||
{{#vardefine:output|{{#var:value}}}} | {{#vardefine:output|{{#var:value}}}} | ||
Line 31: | Line 31: | ||
}} | }} | ||
+ | <pre>{{numberswitch | ||
+ | | number=1991-01 | ||
+ | | this is the default | ||
+ | | 1990-01=number greater or equals 2 | ||
+ | | 1991-12=number greater or equals 3 | ||
+ | | 1993-04=number greater or equals 4 | ||
+ | }}</pre> | ||
+ | |||
+ | returns: | ||
+ | |||
+ | {{numberswitch | ||
+ | | number=1990-01 | ||
+ | | this is the default | ||
+ | | 1990-01=number greater or equals 1990-01 | ||
+ | | 1991-12=number greater or equals 1991-12 | ||
+ | | 1993-04=number greater or equals 1993-04 | ||
+ | }} | ||
[[Category:Sega Retro templates]] | [[Category:Sega Retro templates]] | ||
</noinclude> | </noinclude> |
Revision as of 08:41, 11 June 2020
Displays different text depending on whether a given number is higher than any of the options
Usage
{{numberswitch | number=3 | this is the default | 2=number greater or equals 2 | 3=number greater or equals 3 | 4=number greater or equals 4 }}
returns:
number greater or equals 3
{{numberswitch | number=1991-01 | this is the default | 1990-01=number greater or equals 2 | 1991-12=number greater or equals 3 | 1993-04=number greater or equals 4 }}
returns:
number greater or equals 1990-01