Template:Sw/doc
This is a documentation subpage for Template:Sw. It contains usage information, categories and other content that is not part of the original Template page. |
This template is like the #switch function, but preserves newlines and spaces from the start and end of the possible values (not from the values used in the conditions, if that is desired, put them all in quotes). A default value is required as second parameter:
- "{{sw|p| d |p| q }}" gives "q".
- "{{sw|r| d |p| q }}" gives "d".
- "{{sw|p| d |p| q |r| s }}" gives "q".
- "{{sw|r| d |p| q |r| s }}" gives "s".
- "{{sw|t| d |p| q |r| s }}" gives "d".
- "{{sw|p| d |p| q |r| s |t| u }}" gives "q".
- "{{sw|r| d |p| q |r| s |t| u }}" gives "s".
- "{{sw|t| d |p| q |r| s |t| u }}" gives "u".
- "{{sw|v| d |p| q |r| s |t| u }}" gives "d".
- "{{sw|v| d |p| q |r| s |t| u |v| w }}" gives "w".
- "{{sw|v| d |p| q |r| s |t| u |v| w |x| y }}" gives "w".
- "{{sw|x| d |p| q |r| s |t| u |v| w |x| y }}" gives "y".
The template can be easily extended to allow more parameters.
#switch
editA call of #switch
essentially takes an n × 2 array (lookup table), with key values in the first column and result values in the second column, a default value, and a control value, and returns the result value corresponding to the first key value which is equal to the control value, if any, and otherwise the default value.
The call of #switch
corresponds to a nesting of #ifeq
, so equality is defined in the same way as for #ifeq
:
{{sw| 1e3 | 0 | 1000 | 1 }}
gives "1".{{#switch: 1e3 | 1000 = 1 | 0 }}
gives "1".{{sw| e | 0 | E | 1 }}
gives "0".{{#switch: e | E = 1 | 0 }}
gives "0".{{sw| pi | 0 | PI | 1 }}
gives "0".{{#switch: pi | PI = 1 | 0 }}
gives "0".
See also
edit