Template:Ifor
From Wikipedia, the free encyclopedia
[edit] Purpose
This template applies a logic function to the contents of the two parameters test1 and test2 to return a then or else pass-in parameter.
- 'then' and 'else' must be defined in the call of the template by |then= something |else= something else
[edit] Usage
{{ifor|test1=|test2=|val1=|val2=|then=|else=}}
If 'test1' equals 'val1' OR 'test2' equals 'val2' the value of 'then' will be displayed. Otherwise, the value of 'else' will be displayed.
- 'displayed' in the case, can be treated as a return value,
... |then=true|else=}}
returns either a null string (nothing) or a true value, which can be tested inside an if statement for branching
- Use in branching (example)
<!-- Note the literal code below would likely malfunction as it contains newlines (included to show and illustrate the nesting behavior of the template within the parser function. The first (outer) if uses inline commenting to eliminate that particular issue and would work well, as the preprocessor just throws them away. The inner, second, if is inside the ifor template. --><!-- -->{{#if:{{ifor{{|test1={{FULLPAGENAME}} |test2={{PAGENAME}} |val1=Wikipedia:Templates |val2=Templates/Examples|then=TRUE }}<!-- (though it's best to leave the trailing else off entirely, |else=}} is fine.) -->|Do something<!-- -->|Do a different something<!-- -->}}