Template:Ifeq
From MHWiki
- To Editors: If you have come to this page to find out why there is a warning in your Edit page, see Template:Use#Warning Explanation.
Overview:
A conditional template, for testing if two strings match. The first two arguments must be simple names appropriate for named parameters of a template, or empty. If they differ, then this ends up using Template:Use with the indirect argument named only once, so the overall expansion is the original fourth argument. But if they match, then this ends up using Template:Use with the indirect argument named twice, so the overall expansion is the second use of the indirect name, or the original third argument. That is, this is an alternate implementation of {{#ifeq:test1|test2|if equal|if differ}}, with a slightly different syntax: {{ifeq|test1|test2|if equal|if differ}}.
Examples:
{{ifeq|{{{1|none}}}|none||[[{{{1}}}]]}} results in parameter 1 converted to a link, unless it is undefined or the literal text "none" in which case nothing is output
{{ifeq|{{NAMESPACE}}|User|[[:Category:blah]]|[[Category:blah]]}} links to the category page if the page in the User namespace, otherwise tags the page with a category
Further illustration: It is assumed in this section that you understand how Template:Use works. You are also assumed to have generally understood how Templates#Parameters work, in particular the sections on numbered parameters and default values.
The base code used in this function is: {{use|indir=a{{{1|}}}|a{{{1|}}}={{{4|}}}|a{{{2|}}}={{{3|}}}}}
Consider the following example (from the syntax above): {{ifeq|test1|test2|if equal|if differ}} For this example, "1" is defined as "test1", "2" is defined as "test2", "3" is defined as "if equal" and "4" is defined as "if differ". Substituting these definitions into the base code, we have: {{use|indir=a{{{test1|}}}|a{{{test1|}}}={{{if differ|}}}|a{{{test2|}}}={{{if equal|}}}}} We now have to consider two scenarios: 1) When "test1" and "test2" are equal, 2) When "test1" and "test2" differ.
1) When "test1" and "test2" are equal, the base code now changes to: {{use|indir=a{{{test1|}}}|a{{{test1|}}}={{{if differ|}}}|a{{{test1|}}}={{{if equal|}}}}} With the duplicate "a{{{test1|}}}" parameters, the latter value will be used when the indirect parameter is expanded, giving the final value of "if equal".
2) When "test1" and "test2" differ, the base code remains unchanged: {{use|indir=a{{{test1|}}}|a{{{test1|}}}={{{if differ|}}}|a{{{test2|}}}={{{if equal|}}}}} As "a{{{test2|}}}" is not the same as "a{{{test1|}}}", it is ignored when the indirect parameter is expanded, giving the final value of "if differ".