Template:Coins
![]() | This template may be substituted. |
![]() | This template uses Lua: |
The {{coins}} and {{unique coins}} templates read unnamed parameters and check whether their values match any of the named parameters' given. When they do, the corresponding named parameter's value will be shown. The difference between the two templates is that in case of repeated identical values {{unique coins}} will show only the first result.
For more complex usages (like defining separator strings or dealing with a variable number of parameters), please refer to {{#invoke:params|coins}} and {{#invoke:params|unique_coins}}.
Usage
[edit]Wikitext:
{{coins|happiness|sadness|unmatched|happiness|scream
| happiness = 🙂
| sadness = 🙁
| scream = 😱
| silence = 😬
}}
Effect:
🙂🙁🙂😱
{{Unique coins}}
[edit]Wikitext:
{{unique coins|happiness|sadness|unmatched|happiness|scream
| happiness = 🙂
| sadness = 🙁
| scream = 😱
| silence = 😬
}}
Effect:
🙂🙁😱
Use cases
[edit]The {{coins}} and {{unique coins}} templates belong to the If-then-else templates category, because they allow to do conditional checks that would be difficult to do otherwise. For instance, the following example checks if at least one parameter among five is empty or not given:
{{#if:{{unique coins|{{{first|}}}|{{{second|}}}|{{{third|}}}|{{{fourth|}}}|{{{fifth|}}}
| = /
}}
| show if at least one is empty
| show if none is empty
}}
The following example instead checks whether at least one parameter is equal to the string “foo” or the string “bar”
{{#if:{{unique coins|{{{first|}}}|{{{second|}}}|{{{third|}}}|{{{fourth|}}}|{{{fifth|}}}
| foo = /
| bar = /
}}
| show if at least one is “foo” or “bar”
| show if none is “foo” or “bar”
}}
A totally different use case instead is that of adding URL flags. For instance, the following imaginary {{Link to expanded wikitext}}
template checks whether any of its four unnamed parameters matches the strings html
, xml
, comments
and removenowiki
(independently of the order); when they do, the strings &wpGenerateRawHtml=1
, &wpGenerateXml=1
, &wpRemoveComments=0
and &wpRemoveNowiki=1
will be respectively appended to the URL (in the same order):
<span class="plainlinks">[{{fullurl:Special:ExpandTemplates|wpInput={{urlencode:{{{input}}}|QUERY}}{{#if:{{{title|}}}|&wpContextTitle={{urlencode:{{{title}}}|QUERY}}}}{{unique coins|{{{1|}}}|{{{2|}}}|{{{3|}}}|{{{4|}}}
| html = &wpGenerateRawHtml=1
| xml = &wpGenerateXml=1
| comments = &wpRemoveComments=0
| removenowiki = &wpRemoveNowiki=1
}}}} {{#if:{{{label|}}}|{{{label|}}}|Expand <code>{{{input}}}</code>}}]</span>
And so, when transcluded as,
{{Link to expanded wikitext|comments|xml
| input = Hello world {<nowiki />{#time:r{{!}}now}<nowiki />}
}}
the following output will be generated:
Checking numeric values
[edit]Because numeric parameter names are treated as parameters whose value (not their name) must be compared, to check whether a given value matches a number a letter can be added before it (usually the letter x
):
{{unique coins|x{{{first|}}}|x{{{second|}}}|x{{{third|}}}|x{{{fourth|}}}|x{{{fifth|}}}
| x12 = (the number 12 is present)
| x42 = (the number 42 is present)
| x187 = (the number 187 is present)
}}