Category:Boolean templates
Contents |
[edit] Purpose
These templates are using the limited support given in the mediawiki wiki code, to implement logic for flow control.
[edit] Note
- These templates are correct in their function, but they are not optimal in their implementation. Even when they are optimized, you can do the same thing without them more optimal.
- You should not use them recklessly, think a couple of times before you are using them, verify if you can implement it some other way.
- If you are using such templates as flow control, you should when you are ready with the template, subst as much as you can.
boolorshould not be used, it is defined only for completeness.- These templates can cause considerable server load. A prefered method is to use meta:Help:Parameter default which can have the same functionality.
[edit] Usage
To make using {{qif}} easier, there are boolean operator templates that can be used as first argument to qif.
In all these templates, an argument is true if it is defined, false otherwise. For each operator, the return value is 1 if true, undef otherwise.
If you don't know what this is about, please read about Boolean logic first. If after reading that article you still don't understand what this is all about, then you perhaps shouldn't use these templates.
| Syntax | Description | Truth | CNF | |||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
{{booland|A|B}}
|
If both A and B are true, return true. |
|
![]() |
|||||||||
{{boolor|A|B}}
|
If A or B (or both) is true, return true. (Equivalent to {{{A|{{{B|}}}}}}) |
|
![]() |
|||||||||
{{boolxor|A|B}}
|
If one of A or B is true (but not both), return true. |
|
![]() |
|||||||||
{{boolnxor|A|B}}
|
If A and B are either both true or both false, return true. |
|
![]() |
|||||||||
{{boolnand|A|B}}
|
If A or B (or both) is false, return true. |
|
![]() |
|||||||||
{{boolnor|A|B}}
|
If both A and B are false, return true. |
|
![]() |
|||||||||
{{boolnot|A}}
|
If A is false, return true, else return false. | ![]() |
[edit] Equality operators
You can use these to check is a parameter has a specific value. Remember that the value can not contain =, also remember that a null-string is false by default, if you want to check if two strings are empty, use {{boolnor}} instead. {{boolne}} can be used to check if user passed = as argument to one parameter ({{boolne|1=foo=bar|2=foo=bar}} will return true).
{{booleq|A|B}}
|
Returns true if A and B are identical. |
{{boolne|A|B}}
|
Returns false if A and B are identical. (This is just a shortcut for {{boolnot|{{booleq|A|B}}}}). |
[edit] How Booleq Works
Suppose the following call to booleq is made:
{{booleq|A|B}}
The booleq template will then make a second template call:
{{eq2|A=1|@=B}}
That is, booleq calls eq2 with two parameters:
-
- The first is named by the first parameter passed to booleq (in this case "A"), and has the value "1".
- The second is named @, and has the value of the second parameter passed to booleq (in this case "B").
The eq2 template then returns:
{{{{{{@}}}|}}}
That is, the value of the parameter which is named by the value of the parameter @. If the two parameters passed to booleq were identical, then the value of @ would be the name of a parameter with value "1", and thus the return value would be "1". In this case, as "A" is not identical to "B", the value of @ does not name an existing parameter, so the return value will be empty.
[edit] Other operators
{{boolexists|PAGE}}
|
Returns true if PAGE exists |
{{boolhash|STRING}}
|
Returns true if STRING starts with an hash |
{{boolspace|STRING}}
|
Returns true if STRING contains spaces |
[edit] Example
Assuming we have a template with the name "X1" that contains the following code:
{{qif
|test={{booland
|1={{booleq
|1={{{1|}}}
|2=foo
}}
|2={{booleq
|1={{{2|}}}
|2=bar
}}
}}
|then=You said '''foo''' '''bar'''
|else=Nah...
}}
If you then call:
- {{X1|foo|bar}}
the result is:
- You said foo bar
Pages in category "Boolean templates"
The following 10 pages are in this category, out of 10 total.






