ढाँचा:Ifequal
This template is used to extend the parser function #ifeq:
to multiple tests.
The template takes up to eight pairs of arguments (i.e., 16 unnamed parameters), tests the odd versus the even parameter values, and returns a TRUE value (a string of characters) if any pair matches using the parser function #ifeq:
, otherwise it returns a FALSE value (an empty string).
{{ifequal|foo|foo}}
→ 1-2{{ifequal|foo|bar}}
→{{ifequal|foo|foo|bar|bar}}
→ 3-41-2{{ifequal|foo|foo|bar|buzz}}
→ 1-2{{ifequal|foo|bar|buzz|buzz}}
→ 3-4{{ifequal|foo|bar|buzz|bat}}
→
The returned values are suitable for testing within simple if-then-else conditionals inside the calling template.
Typical example
सम्पादन{{#if: {{ifequal|{{{1}}}|one|{{{2}}}|two|{{{3}}}|three}} | Yes, we | No, we don't }} have a match.
Assuming this code is inside of a template that can be called with three unnamed parameter values:
- The
{{ifequal}}
call returns TRUE if the first unnamed parameter has the value "one" OR the second has the value "two" OR the third has the value "three", in which case the code will build the string: "Yes, we have a match." - The
{{ifequal}}
call returns FALSE if none match, in which case it will build the string: "No, we don't have a match."
Behavior with empty strings (unset parameter values)
सम्पादनAssuming the parameter values referred to here have not been set in the calling template:
{{ifequal||}}
→{{ifequal|{{{foo|}}}|}}
→{{ifequal|{{{foo|}}}|{{{bar|}}}}}
→
Note how empty strings are not considered equal in any of these cases.
But beware: in the following two examples, if the parameters have bot been set, the literal strings "{{{foo}}}" and "{{{bar}}}" are used in their place.
{{ifequal|{{{foo}}}|}}
→{{ifequal|{{{foo}}}|{{{bar}}}}}
→
The difference is the presence or absence of a vertical-bar character (|
) following "foo" and "bar". See Help:Template#Handling parameters for more information about this.
To detect whether parameter values are set or unset, use the #if: parser function instead of this template.
See also
सम्पादन{{ifeqall}}
— Compares one comparison string against up to 10 case strings with optional result string and default result string outputs.{{ifeqany}}
— Compares up to 24 case strings against each other with result string and default result string outputs.{{ifor}}
— Compares up to 30 comparison strings against an equal number of case strings with optional result string and default result string outputs.{{=}}
— Returns an equal sign.