<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://battleint.net/index.php?action=history&amp;feed=atom&amp;title=Help%3AConditional_expressions</id>
	<title>Help:Conditional expressions - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://battleint.net/index.php?action=history&amp;feed=atom&amp;title=Help%3AConditional_expressions"/>
	<link rel="alternate" type="text/html" href="https://battleint.net/index.php?title=Help:Conditional_expressions&amp;action=history"/>
	<updated>2026-11-22T10:55:26Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.44.0</generator>
	<entry>
		<id>https://battleint.net/index.php?title=Help:Conditional_expressions&amp;diff=200805&amp;oldid=prev</id>
		<title>Tungstenchan: Text replacement - &quot;BattleTechWiki&quot; to &quot;BattleIntelligence&quot;</title>
		<link rel="alternate" type="text/html" href="https://battleint.net/index.php?title=Help:Conditional_expressions&amp;diff=200805&amp;oldid=prev"/>
		<updated>2025-05-01T05:13:33Z</updated>

		<summary type="html">&lt;p&gt;Text replacement - &amp;quot;BattleTechWiki&amp;quot; to &amp;quot;BattleIntelligence&amp;quot;&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Revision as of 00:13, 1 May 2025&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l1&quot;&gt;Line 1:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 1:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;{{for|more detailed instructions|mw:Help:Extension:ParserFunctions}}&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;{{for|more detailed instructions|mw:Help:Extension:ParserFunctions}}&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;{{&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;BattleTechWiki &lt;/del&gt;how-to|H:CONEX|H:CX}}&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;{{&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;BattleIntelligence &lt;/ins&gt;how-to|H:CONEX|H:CX}}&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;This page describes how to use various [[BTW:Parser functions|parser functions]] to display different results based on detected conditions in a page or [[Help:Template|template]].&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;This page describes how to use various [[BTW:Parser functions|parser functions]] to display different results based on detected conditions in a page or [[Help:Template|template]].&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>Tungstenchan</name></author>
	</entry>
	<entry>
		<id>https://battleint.net/index.php?title=Help:Conditional_expressions&amp;diff=171968&amp;oldid=prev</id>
		<title>imported&gt;Deadfire: Creation</title>
		<link rel="alternate" type="text/html" href="https://battleint.net/index.php?title=Help:Conditional_expressions&amp;diff=171968&amp;oldid=prev"/>
		<updated>2023-09-19T22:41:16Z</updated>

		<summary type="html">&lt;p&gt;Creation&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;{{for|more detailed instructions|mw:Help:Extension:ParserFunctions}}&lt;br /&gt;
{{BattleTechWiki how-to|H:CONEX|H:CX}}&lt;br /&gt;
This page describes how to use various [[BTW:Parser functions|parser functions]] to display different results based on detected conditions in a page or [[Help:Template|template]].&lt;br /&gt;
&lt;br /&gt;
Here is a quick summary of these functions in terms of how they treat their input (the function names are linked to more detailed descriptions of them found below on this page):&lt;br /&gt;
* &amp;lt;code&amp;gt;[[#if]]&amp;lt;/code&amp;gt; checks the truth value of a string&lt;br /&gt;
* &amp;lt;code&amp;gt;[[#ifeq]]&amp;lt;/code&amp;gt; checks whether two strings or numbers are equal&lt;br /&gt;
* &amp;lt;code&amp;gt;[[#switch]]&amp;lt;/code&amp;gt; compares a string to a set of possible values&lt;br /&gt;
* &amp;lt;code&amp;gt;[[#expr]]&amp;lt;/code&amp;gt; evaluates a mathematical expression&lt;br /&gt;
* &amp;lt;code&amp;gt;[[#ifexpr]]&amp;lt;/code&amp;gt; evaluates a mathematical expression and acts on the truth value of the result&lt;br /&gt;
* &amp;lt;code&amp;gt;[[#iferror]]&amp;lt;/code&amp;gt; checks whether a string (often an expression inside of &amp;lt;code&amp;gt;#expr&amp;lt;/code&amp;gt;) triggers a parser error&lt;br /&gt;
* &amp;lt;code&amp;gt;[[#ifexist]]&amp;lt;/code&amp;gt; checks whether a page with a given title exists on the wiki (including image/media files)&lt;br /&gt;
&lt;br /&gt;
For the use of these functions in tables, see [[w:Help:Conditional tables]].&lt;br /&gt;
&lt;br /&gt;
== Summary ==&lt;br /&gt;
The basic syntax (and use) of each function is as follows:&lt;br /&gt;
* &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;{{#if:&amp;lt;/nowiki&amp;gt; &amp;#039;&amp;#039;test string&amp;#039;&amp;#039; | &amp;#039;&amp;#039;value if true&amp;#039;&amp;#039; | &amp;#039;&amp;#039;value if false&amp;#039;&amp;#039; }}&amp;lt;/code&amp;gt;&lt;br /&gt;
*: (selects one of two values based on whether the test string is true or false)&lt;br /&gt;
* &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;{{#ifeq:&amp;lt;/nowiki&amp;gt; &amp;#039;&amp;#039;string 1&amp;#039;&amp;#039; | &amp;#039;&amp;#039;string 2&amp;#039;&amp;#039; | &amp;#039;&amp;#039;value if equal&amp;#039;&amp;#039; | &amp;#039;&amp;#039;value if unequal&amp;#039;&amp;#039; }}&amp;lt;/code&amp;gt;&lt;br /&gt;
*: (selects one of two values based on whether the two strings are equal—a numerical comparison is done whenever that is possible)&lt;br /&gt;
* &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;{{#switch:&amp;lt;/nowiki&amp;gt; &amp;#039;&amp;#039;test string&amp;#039;&amp;#039; | &amp;#039;&amp;#039;case1&amp;#039;&amp;#039; = &amp;#039;&amp;#039;value for case 1&amp;#039;&amp;#039; | ... | &amp;#039;&amp;#039;default&amp;#039;&amp;#039; }}&amp;lt;/code&amp;gt;&lt;br /&gt;
*: (chooses between multiple alternatives based on the value of the test string—basically equivalent to a chain of &amp;lt;code&amp;gt;#ifeq&amp;lt;/code&amp;gt; tests, but &amp;#039;&amp;#039;much&amp;#039;&amp;#039; more efficient)&lt;br /&gt;
* &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;{{#expr:&amp;lt;/nowiki&amp;gt; &amp;#039;&amp;#039;expression&amp;#039;&amp;#039; }}&amp;lt;/code&amp;gt;&lt;br /&gt;
*: (evaluates a given expression; see [[w:Help:Calculation]] for details)&lt;br /&gt;
* &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;{{#ifexpr:&amp;lt;/nowiki&amp;gt; &amp;#039;&amp;#039;expression&amp;#039;&amp;#039; | &amp;#039;&amp;#039;value if true&amp;#039;&amp;#039; | &amp;#039;&amp;#039;value if false&amp;#039;&amp;#039; }}&amp;lt;/code&amp;gt;&lt;br /&gt;
*: (selects one of two values based on the truth value of an evaluated expression)&lt;br /&gt;
* &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;{{#iferror:&amp;lt;/nowiki&amp;gt; &amp;#039;&amp;#039;test string&amp;#039;&amp;#039; | &amp;#039;&amp;#039;value if error&amp;#039;&amp;#039; | &amp;#039;&amp;#039;value if no error&amp;#039;&amp;#039; }}&amp;lt;/code&amp;gt;&lt;br /&gt;
*: (selects one of two values based on whether the test string generates a parser error)&lt;br /&gt;
* &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;{{#ifexist:&amp;lt;/nowiki&amp;gt; &amp;#039;&amp;#039;page title&amp;#039;&amp;#039; | &amp;#039;&amp;#039;value if exists&amp;#039;&amp;#039; | &amp;#039;&amp;#039;value if doesn&amp;#039;t exist&amp;#039;&amp;#039; }}&amp;lt;/code&amp;gt;&lt;br /&gt;
*: (selects one of two values depending on the existence of a page having the given title)&lt;br /&gt;
&lt;br /&gt;
{{anchor|Truth}}Note that &amp;quot;truth&amp;quot; is interpreted very differently by the string-based &amp;lt;code&amp;gt;[[#if]]&amp;lt;/code&amp;gt; function and the numerically oriented functions &amp;lt;code&amp;gt;[[#expr]]&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;[[#ifexpr]]&amp;lt;/code&amp;gt;. A string is considered true if it contains at least one non-whitespace character (thus, for example, the &amp;lt;code&amp;gt;#if&amp;lt;/code&amp;gt; function interprets the strings &amp;quot;0&amp;quot; and &amp;quot;FALSE&amp;quot; as true values, not false). Any string containing only whitespace or no characters at all will be treated as false (thus &amp;lt;code&amp;gt;#if&amp;lt;/code&amp;gt; interprets &amp;quot;&amp;amp;nbsp;&amp;quot; and &amp;quot;&amp;quot;, as well as undefined parameters, as false values). On the other hand, in the expressions evaluated by &amp;lt;code&amp;gt;#expr&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;#ifexpr&amp;lt;/code&amp;gt;, Boolean operators like &amp;lt;code&amp;gt;and&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;or&amp;lt;/code&amp;gt;, and &amp;lt;code&amp;gt;not&amp;lt;/code&amp;gt; interpret the numerical value 0 as false and any other number as true. In terms of output, Boolean operations return 1 for a true value and 0 for false (and these are treated as ordinary numbers by the numerical operators). Non-numerical strings (including most uses of empty strings and undefined parameters) will cause &amp;lt;code&amp;gt;#expr&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;#ifexpr&amp;lt;/code&amp;gt; to report an error.&lt;br /&gt;
&lt;br /&gt;
Also note that all leading and trailing [[w:Whitespace character|whitespace]] within each of the parts of a parser function call gets stripped out, allowing the calls to be formatted with extra whitespace for better readability. For example:&lt;br /&gt;
&amp;lt;!-- Note: change the next example in this section if you change this one! --&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;wikitext&amp;quot;&amp;gt;&lt;br /&gt;
{{#if: {{{xx|}}}&lt;br /&gt;
   | parameter xx value is true&lt;br /&gt;
   | parameter xx value is false&lt;br /&gt;
}}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
Here, only the spaces in the strings &amp;quot;parameter xx value is true&amp;quot; and &amp;quot;parameter xx value is true&amp;quot; are significant. All other whitespace is ignored. Thus, the construct above is equivalent to the following call:&lt;br /&gt;
&amp;lt;!-- Note: change the preceding example if you change this one! --&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;wikitext&amp;quot;&amp;gt;&lt;br /&gt;
{{#if:{{{xx|}}}|parameter xx value is true|parameter xx value is false}}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In any part of a parser function call where a string is expected, one can use a literal string, a template call, a parser function call, or some other [[Help:Magic words|magic word]].&lt;br /&gt;
&lt;br /&gt;
== &amp;lt;span id=&amp;quot;if&amp;quot;&amp;gt;&amp;lt;/span&amp;gt;Using &amp;lt;code&amp;gt;#if&amp;lt;/code&amp;gt; ==&lt;br /&gt;
: &amp;#039;&amp;#039;See also: the {{tlx|if}} template&amp;#039;&amp;#039;&lt;br /&gt;
The &amp;lt;code&amp;gt;#if&amp;lt;/code&amp;gt; function selects one of two alternatives based on the truth value of a test string.&lt;br /&gt;
&lt;br /&gt;
: &amp;#039;&amp;#039;&amp;#039;&amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;{{#if:&amp;lt;/nowiki&amp;gt; &amp;#039;&amp;#039;test string&amp;#039;&amp;#039; | &amp;#039;&amp;#039;value if true&amp;#039;&amp;#039; | &amp;#039;&amp;#039;value if false&amp;#039;&amp;#039; }}&amp;lt;/code&amp;gt;&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
[[#Truth|As explained above]], a string is considered true if it contains at least one non-whitespace character. Any string containing only whitespace or no characters at all will be treated as false.&lt;br /&gt;
&lt;br /&gt;
Undefined parameter values are tricky: if the first positional parameter was not defined in the template call, then &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;{{{1}}}&amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt; will evaluate to the literal string &amp;quot;&amp;lt;nowiki&amp;gt;{{{1}}}&amp;lt;/nowiki&amp;gt;&amp;quot; (i.e., the 7-character string containing three sets of curly braces around the number 1), which is a &amp;#039;&amp;#039;true&amp;#039;&amp;#039; value. (This problem exists for both [[Help:Template#Handling parameters|named and positional]] parameters.) But &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;{{{1|}}}&amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt; will evaluate to the empty string (a &amp;#039;&amp;#039;false&amp;#039;&amp;#039; value) because the [[w:vertical bar|vertical bar]] or pipe character, &amp;lt;code&amp;gt;&amp;quot;|&amp;quot;&amp;lt;/code&amp;gt;, immediately following the parameter name specifies a default value (here an empty string because there is nothing between the pipe and the first closing curly brace) as a &amp;quot;fallback&amp;quot; value to be used if the parameter is undefined.&lt;br /&gt;
&lt;br /&gt;
This function can be used to check whether a parameter has been passed to a template with a true value.&lt;br /&gt;
&lt;br /&gt;
Examples:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;wikitext&amp;quot;&amp;gt;&lt;br /&gt;
{{#if: {{{1|}}}&lt;br /&gt;
   | first positional parameter has a true value&lt;br /&gt;
   | first positional parameter has a false value (or no value)&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
{{#if: {{{xx|}}}&lt;br /&gt;
   | named parameter xx has a true value&lt;br /&gt;
   | named parameter xx has a false value (or no value)&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
{{#if: {{{xx|}}}{{{yy|}}}&lt;br /&gt;
   | either xx or yy has a true value, or both are true&lt;br /&gt;
   | both xx and yy have a false value (or no value)&lt;br /&gt;
}}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Testing whether both of two parameters are true requires a little more effort. For example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;wikitext&amp;quot;&amp;gt;&lt;br /&gt;
{{#if: {{{xx|}}}&lt;br /&gt;
   | {{#if: {{{yy|}}}&lt;br /&gt;
       | both xx and yy have true values&lt;br /&gt;
       | xx is true but not yy&lt;br /&gt;
     }}&lt;br /&gt;
   | both xx and yy are false&lt;br /&gt;
}}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note that nesting &amp;lt;code&amp;gt;#if&amp;lt;/code&amp;gt; functions like this gets very resource-intensive very fast. On some wikis, even seven levels of nesting might exceed resource limits.&lt;br /&gt;
&lt;br /&gt;
See the discussion of &amp;lt;code&amp;gt;[[#ifeq]]&amp;lt;/code&amp;gt; for how to detect whether a parameter has been defined regardless of whether its value is true or false.&lt;br /&gt;
&lt;br /&gt;
== &amp;lt;span id=&amp;quot;ifeq&amp;quot;&amp;gt;&amp;lt;/span&amp;gt;Using &amp;lt;code&amp;gt;#ifeq&amp;lt;/code&amp;gt; ==&lt;br /&gt;
: &amp;#039;&amp;#039;See also: the {{tlx|ifeq}} template&amp;#039;&amp;#039;&lt;br /&gt;
The &amp;lt;code&amp;gt;#ifeq&amp;lt;/code&amp;gt; function selects one of two alternatives based on whether two test strings are equal to each other.&lt;br /&gt;
&lt;br /&gt;
: &amp;#039;&amp;#039;&amp;#039;&amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;{{#ifeq:&amp;lt;/nowiki&amp;gt; &amp;#039;&amp;#039;string 1&amp;#039;&amp;#039; | &amp;#039;&amp;#039;string 2&amp;#039;&amp;#039; | &amp;#039;&amp;#039;value if equal&amp;#039;&amp;#039; | &amp;#039;&amp;#039;value if not equal&amp;#039;&amp;#039; }}&amp;lt;/code&amp;gt;&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
If both strings are valid numerical values, they are compared as numbers, rather than as literal strings:&lt;br /&gt;
&lt;br /&gt;
: &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;{{#ifeq: 01 | 1 | equal | not equal }}&amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt; → &amp;#039;&amp;#039;&amp;#039;{{#ifeq: 01 | 1 | equal | not equal }}&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
: &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;{{#ifeq: x01 | x1 | equal | not equal }}&amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt; → &amp;#039;&amp;#039;&amp;#039;{{#ifeq: x01 | x1 | equal | not equal }}&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
: &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;{{#ifeq: 2.000 | 002 | equal | not equal }}&amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt; → &amp;#039;&amp;#039;&amp;#039;{{#ifeq: 2.000 | 002 | equal | not equal }}&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
: &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;{{#ifeq: 2.5 | 2+.5 | equal | not equal }}&amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt; → &amp;#039;&amp;#039;&amp;#039;{{#ifeq: 2.5 | 2+.5 | equal | not equal }}&amp;#039;&amp;#039;&amp;#039; (arithmetic!)&lt;br /&gt;
: &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;{{#ifeq: 2*10^3 | 2000 | equal | not equal }}&amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt; → &amp;#039;&amp;#039;&amp;#039;{{#ifeq: 2*10^3 | 2000 | equal | not equal }}&amp;#039;&amp;#039;&amp;#039; (arithmetic!)&lt;br /&gt;
: &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;{{#ifeq: 2E3 | 2000 | equal | not equal }}&amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt; → &amp;#039;&amp;#039;&amp;#039;{{#ifeq: 2E3 | 2000 | equal | not equal }}&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
As seen in the 4th and 5th examples, mathematical expressions are &amp;#039;&amp;#039;not&amp;#039;&amp;#039; evaluated. They are treated as regular strings. But &amp;lt;code&amp;gt;[[#expr]]&amp;lt;/code&amp;gt; can be used to evaluate such expressions.&lt;br /&gt;
&lt;br /&gt;
: &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;{{#ifeq: {{#expr:2*10^3}} | 2000 | equal | not equal }}&amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt; → &amp;#039;&amp;#039;&amp;#039;{{#ifeq: {{#expr:2*10^3}} | 2000 | equal | not equal }}&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
String comparisons are [[w:case-sensitive|case-sensitive]]:&lt;br /&gt;
&lt;br /&gt;
: &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;{{#ifeq: King | king | equal | not equal }}&amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt; → &amp;#039;&amp;#039;&amp;#039;{{#ifeq: King | king | equal | not equal }}&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
For case-insensitive checking, use [[Help:Magic words#Formatting|the &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;{{lc:}}&amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;{{uc:}}&amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt; function]] to force the strings to all lower- or upper-case. This is most useful when dealing with parameter values:&lt;br /&gt;
&lt;br /&gt;
: &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;{{#ifeq: {{lc:King}} | king | equal | not equal }}&amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt; → &amp;#039;&amp;#039;&amp;#039;{{#ifeq: {{lc:King}} | king | equal | not equal }}&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
: &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;{{#ifeq: {{lc: {{{position}}} }} | top | code if true | code if false }}&amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the second example, the values &amp;quot;top&amp;quot;, &amp;quot;Top&amp;quot;, and &amp;quot;TOP&amp;quot; will all result in successful matches.&lt;br /&gt;
&lt;br /&gt;
This parser function can be used to detect whether a template parameter is defined, even if it has been set to a false value. For example, to check whether the first positional parameter has been passed to a template (note that the strings &amp;quot;&amp;lt;code&amp;gt;+&amp;lt;/code&amp;gt;&amp;quot; and &amp;quot;&amp;lt;code&amp;gt;-&amp;lt;/code&amp;gt;&amp;quot; can be any two different non-whitespace strings):&lt;br /&gt;
&lt;br /&gt;
: &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;{{#ifeq: {{{1|+}}} | {{{1|-}}} | 1 is defined | 1 is undefined }}&amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To be specific, here&amp;#039;s what this code generates when called in the following ways:&lt;br /&gt;
&lt;br /&gt;
: &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;{{&amp;lt;/nowiki&amp;gt;&amp;lt;var&amp;gt;template-name&amp;lt;/var&amp;gt;}}&amp;lt;/code&amp;gt; → &amp;#039;&amp;#039;&amp;#039;1 is undefined&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
: &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;{{&amp;lt;/nowiki&amp;gt;&amp;lt;var&amp;gt;template-name&amp;lt;/var&amp;gt;|}}&amp;lt;/code&amp;gt; → &amp;#039;&amp;#039;&amp;#039;1 is defined&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
: &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;{{&amp;lt;/nowiki&amp;gt;&amp;lt;var&amp;gt;template-name&amp;lt;/var&amp;gt;|1=}}&amp;lt;/code&amp;gt; → &amp;#039;&amp;#039;&amp;#039;1 is defined&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
: &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;{{&amp;lt;/nowiki&amp;gt;&amp;lt;var&amp;gt;template-name&amp;lt;/var&amp;gt;|1=foo}}&amp;lt;/code&amp;gt; → &amp;#039;&amp;#039;&amp;#039;1 is defined&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
See [[mw:Help:Extension:ParserFunctions##ifeq]]&amp;lt;!-- the two &amp;quot;#&amp;quot; characters are necessary --&amp;gt; for more details, including possible counterintuitive results due to the way this function is implemented.&lt;br /&gt;
&lt;br /&gt;
== &amp;lt;span id=&amp;quot;switch&amp;quot;&amp;gt;&amp;lt;/span&amp;gt;Using &amp;lt;code&amp;gt;#switch&amp;lt;/code&amp;gt; ==&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;code&amp;gt;#switch&amp;lt;/code&amp;gt; function selects between multiple alternatives based on an input string.&lt;br /&gt;
&lt;br /&gt;
: &amp;#039;&amp;#039;&amp;#039;&amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;{{#switch:&amp;lt;/nowiki&amp;gt; &amp;#039;&amp;#039;test string&amp;#039;&amp;#039; | &amp;#039;&amp;#039;case1&amp;#039;&amp;#039; = &amp;#039;&amp;#039;value for case 1&amp;#039;&amp;#039; | ... | &amp;#039;&amp;#039;default value&amp;#039;&amp;#039; }}&amp;lt;/code&amp;gt;&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
Equivalent to the [[w:switch statement|switch statement]] found in some programming laguages, it is a convenient way of dealing with multiple cases without having to chain lots of &amp;lt;code&amp;gt;#if&amp;lt;/code&amp;gt; functions together. However, note that performance suffers when there are more than 100 alternatives. Placing common values earlier in the list of cases can cause the function to execute significantly faster.&lt;br /&gt;
&lt;br /&gt;
For each case, either side of the equals sign &amp;quot;&amp;lt;code&amp;gt;=&amp;lt;/code&amp;gt;&amp;quot; can be a simple string, a call to a parser function (including &amp;lt;code&amp;gt;#expr&amp;lt;/code&amp;gt; to evaulate expressions), or a template call. If any cases are not associated with a value (i.e., no equals sign is used), the next specified value will be used. This allows multiple cases to share the same value without having to specify that value repeatedly (as seen in the example below).&lt;br /&gt;
&lt;br /&gt;
If no matching case is found, then the default value is used. This is usually specified last with no associated &amp;quot;&amp;#039;&amp;#039;case&amp;#039;&amp;#039;&amp;quot; value, as seen in the syntax summary above, but it can also be specified at any point after the test string if the construct &amp;lt;code&amp;gt;| #default = &amp;#039;&amp;#039;value&amp;#039;&amp;#039;&amp;lt;/code&amp;gt; is used (see the second example below). If no default is specified in either way, then a null string will be returned when no cases match the input string.&lt;br /&gt;
&lt;br /&gt;
This function in particular benefits from being set up in a multiline format.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;wikitext&amp;quot;&amp;gt;&lt;br /&gt;
{{#switch: {{{x|}}}&lt;br /&gt;
 | 1 = one&lt;br /&gt;
 | 2 = two&lt;br /&gt;
 | 3 = three&lt;br /&gt;
 | 4 = four&lt;br /&gt;
 | 5&lt;br /&gt;
 | 6&lt;br /&gt;
 | 7 = in the range 5 to 7&lt;br /&gt;
 | other&lt;br /&gt;
}}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here, if the value of the template parameter &amp;lt;code&amp;gt;x&amp;lt;/code&amp;gt; is the string &amp;quot;1&amp;quot;, then the output will be the string &amp;quot;one&amp;quot;; if &amp;quot;2&amp;quot;, then &amp;quot;two&amp;quot;; and so forth. But for any of the values &amp;quot;5&amp;quot;, &amp;quot;6&amp;quot; or &amp;quot;7&amp;quot;, the output will be the string &amp;quot;in the range 5 to 7&amp;quot;. For any other value, or a null value, it will return the string &amp;quot;other&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
The following example is equivalent to the previous one:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;wikitext&amp;quot;&amp;gt;&lt;br /&gt;
{{#switch: {{{x|}}}&lt;br /&gt;
 | #default = other&lt;br /&gt;
 | 1 = one&lt;br /&gt;
 | 2 = two&lt;br /&gt;
 | 3 = three&lt;br /&gt;
 | 4 = four&lt;br /&gt;
 | 5|6|7 = in the range 5 to 7&lt;br /&gt;
}}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
See [[Help:Switch parser function]] for a full description and more examples.&lt;br /&gt;
&lt;br /&gt;
== &amp;lt;span id=&amp;quot;expr&amp;quot;&amp;gt;&amp;lt;/span&amp;gt;Using &amp;lt;code&amp;gt;#expr&amp;lt;/code&amp;gt; ==&lt;br /&gt;
The &amp;lt;code&amp;gt;#expr&amp;lt;/code&amp;gt; function evaluates mathematical (including Boolean) expressions. While not itself a conditional function, it is often used inside of those functions, so it is briefly described here. See [[meta:Help:Calculation]] for further details.&lt;br /&gt;
&lt;br /&gt;
: &amp;#039;&amp;#039;&amp;#039;&amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;{{#expr:&amp;lt;/nowiki&amp;gt; &amp;#039;&amp;#039;expression&amp;#039;&amp;#039; }}&amp;lt;/code&amp;gt;&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
Unlike the &amp;lt;code&amp;gt;[[#if]]&amp;lt;/code&amp;gt; function, all values in the &amp;lt;code&amp;gt;&amp;#039;&amp;#039;expression&amp;#039;&amp;#039;&amp;lt;/code&amp;gt; evaluated by &amp;lt;code&amp;gt;#expr&amp;lt;/code&amp;gt; are assumed to be numerical. It does not work with arbitrary strings. For the purpose of its Boolean operations (e.g., &amp;lt;code&amp;gt;and&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;or&amp;lt;/code&amp;gt;, and &amp;lt;code&amp;gt;not&amp;lt;/code&amp;gt;), false is represented by 0 and true by 1; these values are treated as regular numbers by the numerical operators. As input, the Boolean operators treat 0 as false and every other number as true. If any non-numerical strings are used, an error will result.&lt;br /&gt;
&lt;br /&gt;
Examples:&lt;br /&gt;
: &amp;lt;syntaxhighlight lang=&amp;quot;wikitext&amp;quot; inline&amp;gt;{{#expr: ( {{{1}}}+{{{xshift}}} - 6 ) * 18.4 }}&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
: &amp;lt;syntaxhighlight lang=&amp;quot;wikitext&amp;quot; inline&amp;gt;{{#expr: ln(7)^3 - abs(-0.344) + floor(5/3) round 3 }}&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
: &amp;lt;syntaxhighlight lang=&amp;quot;wikitext&amp;quot; inline&amp;gt;{{#expr: {{{n}}}&amp;gt;0 and {{{n}}}&amp;lt;1.0 }}&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note that these examples assume that all parameters referred to are defined and have numerical values. If this is not the case, errors will occur. See &amp;lt;code&amp;gt;[[#iferror]]&amp;lt;/code&amp;gt; for one way to handle errors.&lt;br /&gt;
&lt;br /&gt;
== &amp;lt;span id=&amp;quot;ifexpr&amp;quot;&amp;gt;&amp;lt;/span&amp;gt;Using &amp;lt;code&amp;gt;#ifexpr&amp;lt;/code&amp;gt; ==&lt;br /&gt;
The &amp;lt;code&amp;gt;#ifexpr&amp;lt;/code&amp;gt; function evaluates an expression in exactly the same way &amp;lt;code&amp;gt;[[#expr]]&amp;lt;/code&amp;gt; does (see the explanation of that function for details), but returns one of two possible values depending on the truth value of the result.&lt;br /&gt;
&lt;br /&gt;
: &amp;#039;&amp;#039;&amp;#039;&amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;{{#ifexpr:&amp;lt;/nowiki&amp;gt; &amp;#039;&amp;#039;expression&amp;#039;&amp;#039; | &amp;#039;&amp;#039;value if true&amp;#039;&amp;#039; | &amp;#039;&amp;#039;value if false&amp;#039;&amp;#039; }}&amp;lt;/code&amp;gt;&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
Examples:&lt;br /&gt;
: &amp;lt;syntaxhighlight lang=&amp;quot;wikitext&amp;quot; inline&amp;gt;{{#ifexpr: ( {{{1}}} + {{{2}}} ) * 2.63 &amp;gt; 45 | above 45 | not above 45 }}&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
: &amp;lt;syntaxhighlight lang=&amp;quot;wikitext&amp;quot; inline&amp;gt;{{#ifexpr: {{{1}}} &amp;gt; 0 and {{{1}}} &amp;lt; 1.0 or {{#ifeq:{{{decimal}}}|yes}} | is decimal | not decimal }}&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
As [[#Truth|explained above]], for the purposes of this function, 0 is false and any other numerical value is true.&lt;br /&gt;
&lt;br /&gt;
: &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;{{#ifexpr: 0 | yes | no }}&amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt; → &amp;#039;&amp;#039;&amp;#039;{{#ifexpr: 0 | yes | no }}&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
: &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;{{#ifexpr: 1 | yes | no }}&amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt; → &amp;#039;&amp;#039;&amp;#039;{{#ifexpr: 1 | yes | no }}&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
: &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;{{#ifexpr: 2 | yes | no }}&amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt; → &amp;#039;&amp;#039;&amp;#039;{{#ifexpr: 2 | yes | no }}&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
An empty input expression evaluates to false.&lt;br /&gt;
&lt;br /&gt;
: &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;{{#ifexpr: | yes | no }}&amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt; → &amp;#039;&amp;#039;&amp;#039;{{#ifexpr: | yes | no }}&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
But invalid input, including input containing non-numerical strings, will display an error message.&lt;br /&gt;
&lt;br /&gt;
: &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;{{#ifexpr: = | yes | no }}&amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt; → &amp;#039;&amp;#039;&amp;#039;{{#ifexpr: = | yes | no }}&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
: &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;{{#ifexpr: A=B | yes | no }}&amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt; → &amp;#039;&amp;#039;&amp;#039;{{#ifexpr: A=B | yes | no }}&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
Under normal circumstances, the function &amp;lt;code&amp;gt;#ifexpr&amp;lt;/code&amp;gt; is equivalent to using the following construct with &amp;lt;code&amp;gt;[[#ifeq]]&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;[[#expr]]&amp;lt;/code&amp;gt; (note the reversal of the &amp;quot;true&amp;quot; and &amp;quot;false&amp;quot; output values, since we are comparing the input result to &amp;quot;0&amp;quot;):&lt;br /&gt;
&lt;br /&gt;
: &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;{{#ifeq: {{#expr:&amp;lt;/nowiki&amp;gt; &amp;#039;&amp;#039;expression&amp;#039;&amp;#039; }} | 0 | &amp;#039;&amp;#039;value if false&amp;#039;&amp;#039; | &amp;#039;&amp;#039;value if true&amp;#039;&amp;#039; }}&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
But any error message generated by &amp;lt;code&amp;gt;#expr&amp;lt;/code&amp;gt; will be seen by &amp;lt;code&amp;gt;#ifeq&amp;lt;/code&amp;gt; as an ordinary string that is not equal to &amp;quot;0&amp;quot;, and thus the &amp;lt;code&amp;gt;&amp;#039;&amp;#039;value if true&amp;#039;&amp;#039;&amp;lt;/code&amp;gt; will be output.&lt;br /&gt;
&lt;br /&gt;
: &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;{{#ifeq: {{#expr: = }} | 0 | yes | no }}&amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt; → &amp;#039;&amp;#039;&amp;#039;{{#ifeq: {{#expr: = }} | 0 | yes | no }}&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
Either or both of the output values may be omitted (or left empty), in which case (assuming the &amp;quot;missing&amp;quot; branch of the construct is reached) no output results.&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;{{#ifexpr: 1 &amp;gt; 0 | yes }}&amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt; → &amp;#039;&amp;#039;&amp;#039;{{#ifexpr: 1 &amp;gt; 0 | yes }}&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
:&amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;{{#ifexpr: 1 &amp;gt; 0 | | no }}&amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt; → &amp;#039;&amp;#039;&amp;#039;&amp;lt;nowiki /&amp;gt;{{#ifexpr: 1 &amp;gt; 0 | | no }}&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&amp;lt;!-- note: &amp;lt;nowiki /&amp;gt; is used in the last example to prevent wiki markup (i.e., apostrophes) from appearing on the page --&amp;gt;&lt;br /&gt;
{{info|To make comparisons based on dates (e.g., if the current date and time is after some other date and time), first convert the time(s) to the number of seconds after January 1, 1970, using the function [[w:Help:Time function|&amp;lt;nowiki&amp;gt;{{#time: U }}&amp;lt;/nowiki&amp;gt;]], then compare (or add, subtract, etc.) those numerical values.}}&lt;br /&gt;
&lt;br /&gt;
See [[mw:Help:Extension:ParserFunctions##ifexpr]]&amp;lt;!-- the two &amp;quot;#&amp;quot; characters are necessary --&amp;gt; for more details, including possible counterintuitive results due to the way this function is implemented.&lt;br /&gt;
&lt;br /&gt;
== &amp;lt;span id=&amp;quot;iferror&amp;quot;&amp;gt;&amp;lt;/span&amp;gt;Using &amp;lt;code&amp;gt;#iferror&amp;lt;/code&amp;gt; ==&lt;br /&gt;
The &amp;lt;code&amp;gt;#iferror&amp;lt;/code&amp;gt; function selects one of two alternatives depending on whether its input triggers an error.&lt;br /&gt;
&lt;br /&gt;
: &amp;#039;&amp;#039;&amp;#039;&amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;{{#iferror:&amp;lt;/nowiki&amp;gt; &amp;#039;&amp;#039;test string&amp;#039;&amp;#039; | &amp;#039;&amp;#039;value if error&amp;#039;&amp;#039; | &amp;#039;&amp;#039;value if correct&amp;#039;&amp;#039; }}&amp;lt;/code&amp;gt;&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
The test string is typically a call to &amp;lt;code&amp;gt;[[#expr]]&amp;lt;/code&amp;gt; or some other parser function, but can be plain text or a template call, in which case an error would be triggered by any HTML object with &amp;lt;code&amp;gt;class=&amp;quot;error&amp;quot;&amp;lt;/code&amp;gt; or any of various [[mw:Help:Templates|template]] errors such as loops and recursions,&amp;lt;!-- different or the same? --&amp;gt; or some other &amp;quot;failsoft&amp;quot;&amp;lt;!-- what is that? --&amp;gt; parser error.&lt;br /&gt;
&lt;br /&gt;
One or both of the return values can be omitted. If the &amp;lt;code&amp;gt;&amp;#039;&amp;#039;value if correct&amp;#039;&amp;#039;&amp;lt;/code&amp;gt; is omitted, the test string is returned if it is not erroneous. If the &amp;lt;code&amp;gt;&amp;#039;&amp;#039;value if error&amp;#039;&amp;#039;&amp;lt;/code&amp;gt; is also omitted, an empty string is returned on an error:&lt;br /&gt;
&lt;br /&gt;
: &amp;lt;syntaxhighlight lang=&amp;quot;wikitext&amp;quot; inline&amp;gt;{{#iferror: {{#expr: 1 + 2 }} | error | correct }}&amp;lt;/syntaxhighlight&amp;gt; → &amp;#039;&amp;#039;&amp;#039;{{#iferror: {{#expr: 1 + 2 }} | error | correct }}&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
: &amp;lt;syntaxhighlight lang=&amp;quot;wikitext&amp;quot; inline&amp;gt;{{#iferror: {{#expr: 1 + X }} | error | correct }}&amp;lt;/syntaxhighlight&amp;gt; → &amp;#039;&amp;#039;&amp;#039;{{#iferror: {{#expr: 1 + X }} | error | correct }}&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
: &amp;lt;syntaxhighlight lang=&amp;quot;wikitext&amp;quot; inline&amp;gt;{{#iferror: {{#expr: 1 + 2 }} | error }}&amp;lt;/syntaxhighlight&amp;gt; → &amp;#039;&amp;#039;&amp;#039;{{#iferror: {{#expr: 1 + 2 }} | error }}&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
: &amp;lt;syntaxhighlight lang=&amp;quot;wikitext&amp;quot; inline&amp;gt;{{#iferror: {{#expr: 1 + X }} | error }}&amp;lt;/syntaxhighlight&amp;gt; → &amp;#039;&amp;#039;&amp;#039;{{#iferror: {{#expr: 1 + X }} | error }}&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
: &amp;lt;syntaxhighlight lang=&amp;quot;wikitext&amp;quot; inline&amp;gt;{{#iferror: {{#expr: 1 + 2 }} }}&amp;lt;/syntaxhighlight&amp;gt; → &amp;#039;&amp;#039;&amp;#039;{{#iferror: {{#expr: 1 + 2 }} }}&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
: &amp;lt;syntaxhighlight lang=&amp;quot;wikitext&amp;quot; inline&amp;gt;{{#iferror: {{#expr: 1 + X }} }}&amp;lt;/syntaxhighlight&amp;gt; → &amp;#039;&amp;#039;&amp;#039;&amp;lt;nowiki /&amp;gt;{{#iferror: {{#expr: 1 + X }} }}&amp;#039;&amp;#039;&amp;#039;&amp;lt;!-- nowiki prevents an apostrophe from appearing on the page --&amp;gt;&lt;br /&gt;
: &amp;lt;syntaxhighlight lang=&amp;quot;wikitext&amp;quot; inline&amp;gt;{{#iferror: {{#expr: . }} | error | correct }}&amp;lt;/syntaxhighlight&amp;gt; → &amp;#039;&amp;#039;&amp;#039;{{#iferror: {{#expr: . }} | error | correct }}&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
: &amp;lt;syntaxhighlight lang=&amp;quot;wikitext&amp;quot; inline&amp;gt;{{#iferror: &amp;lt;strong class=&amp;quot;error&amp;quot;&amp;gt;a&amp;lt;/strong&amp;gt; | error | correct }}&amp;lt;/syntaxhighlight&amp;gt; → &amp;#039;&amp;#039;&amp;#039;{{#iferror: &amp;lt;strong class=&amp;quot;error&amp;quot;&amp;gt;a&amp;lt;/strong&amp;gt; | error | correct }}&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
== &amp;lt;span id=&amp;quot;ifexist&amp;quot;&amp;gt;&amp;lt;/span&amp;gt;Using &amp;lt;code&amp;gt;#ifexist&amp;lt;/code&amp;gt; ==&lt;br /&gt;
{{shortcut|HELP:ifexist}}&lt;br /&gt;
The &amp;lt;code&amp;gt;#ifexist&amp;lt;/code&amp;gt; function selects one of two alternatives depending on whether a page exists at the specified title.&lt;br /&gt;
&lt;br /&gt;
: &amp;#039;&amp;#039;&amp;#039;&amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;{{#ifexist:&amp;lt;/nowiki&amp;gt; &amp;#039;&amp;#039;page title&amp;#039;&amp;#039; | &amp;#039;&amp;#039;value if page exists&amp;#039;&amp;#039; | &amp;#039;&amp;#039;value if page doesn&amp;#039;t exist&amp;#039;&amp;#039; }}&amp;lt;/code&amp;gt;&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
The page can be in any [[Help:Namespace|namespace]], so it can be an article or &amp;quot;content page&amp;quot;, an image or other media file, a category, etc. The actual content of the page is irrelevant, so it may be empty or a [[Help:Redirect|redirect]]. Titles that would result in &amp;#039;&amp;#039;redlinks&amp;#039;&amp;#039; do not exist (and, as with &amp;#039;&amp;#039;redlinks&amp;#039;&amp;#039;, checking for the existence of a nonexistent page causes the title to appear on [[Special:WantedPages]]).&lt;br /&gt;
&lt;br /&gt;
The checking is extremely fast, but has been limited to 500 instances per page because it is considered an &amp;quot;[[mw:Manual:$wgExpensiveParserFunctionLimit|expensive parser function]]&amp;quot;. (However, multiple checks of the &amp;#039;&amp;#039;same&amp;#039;&amp;#039; title on the same page do not count as multiple instances, because the results of the first check is cached and reused for the subsequent checks.)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== &amp;lt;span id=&amp;quot;Conditionals for templates&amp;quot;&amp;gt;&amp;lt;/span&amp;gt;Checking for template parameters ==&lt;br /&gt;
A common idiom encountered in template coding is the &amp;quot;chain of fallback values&amp;quot;, as seen in this example:&lt;br /&gt;
&lt;br /&gt;
: &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;{{{&amp;lt;/nowiki&amp;gt;1|{{color|purple|&amp;lt;nowiki&amp;gt;{{{url|&amp;lt;/nowiki&amp;gt;{{color|darkgreen|&amp;lt;nowiki&amp;gt;{{{URL|}}}&amp;lt;/nowiki&amp;gt;}}&amp;lt;nowiki&amp;gt;}}}&amp;lt;/nowiki&amp;gt;}}&amp;lt;nowiki&amp;gt;}}}&amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&amp;lt;!-- note: can&amp;#039;t use whitespace to pretty this up! --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here, if the first positional parameter is defined, then its value will be used. If it is undefined, then the parameter named &amp;lt;code&amp;gt;url&amp;lt;/code&amp;gt; will be checked and if it is defined, then its value will be used. If both the first positional parameter and &amp;lt;code&amp;gt;url&amp;lt;/code&amp;gt; are undefined, then the parameter named &amp;lt;code&amp;gt;URL&amp;lt;/code&amp;gt; is checked: if it is defined, its value is used; if not, then the empty string will be used.&lt;br /&gt;
&lt;br /&gt;
The problem is, this construct tends to be interpreted as being equivalent to:&lt;br /&gt;
&lt;br /&gt;
: &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;{{#if: {{{1|}}} | {{{1}}} |&amp;lt;/nowiki&amp;gt; {{color|purple|&amp;lt;nowiki&amp;gt;{{#if: {{{url|}}} | {{{url}}} |&amp;lt;/nowiki&amp;gt; {{color|darkgreen|&amp;lt;nowiki&amp;gt;{{#if: {{{URL|}}} | {{{URL}}} }}&amp;lt;/nowiki&amp;gt;}} &amp;lt;nowiki&amp;gt;}}&amp;lt;/nowiki&amp;gt;}} &amp;lt;nowiki&amp;gt;}}&amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
and it is &amp;#039;&amp;#039;&amp;#039;not&amp;#039;&amp;#039;&amp;#039;. The difference is that the first construct, using default values, depends on the &amp;#039;&amp;#039;definedness&amp;#039;&amp;#039; of the parameters, whereas the second construct, using &amp;lt;code&amp;gt;#if&amp;lt;/code&amp;gt; functions, depends on the &amp;#039;&amp;#039;truth value&amp;#039;&amp;#039; of the parameters. These are two very different things.&lt;br /&gt;
&lt;br /&gt;
If any of the parameters in the chain of fallback values (in the first construct) have been set to an empty value (or only whitespace) in the template call, then that empty value will be used instead of &amp;quot;falling back&amp;quot; to the next parameter in the chain. So, for example, if the template is called in either of these two ways:&lt;br /&gt;
&lt;br /&gt;
: &amp;lt;syntaxhighlight lang=&amp;quot;wikitext&amp;quot; inline&amp;gt;{{template-name||url=https://example.com/}}&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
: &amp;lt;syntaxhighlight lang=&amp;quot;wikitext&amp;quot; inline&amp;gt;{{template-name|url=https://example.com/|}}&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The first positional parameter &amp;#039;&amp;#039;has&amp;#039;&amp;#039; been defined: its value is the empty string. Thus, the value of &amp;lt;code&amp;gt;url&amp;lt;/code&amp;gt; is irrelevant. The template never &amp;quot;gets to&amp;quot; that value.&lt;br /&gt;
&lt;br /&gt;
Similarly, if the template is called in this way:&lt;br /&gt;
&lt;br /&gt;
: &amp;lt;syntaxhighlight lang=&amp;quot;wikitext&amp;quot; inline&amp;gt;{{template-name|url=|URL=https://example.com/}}&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The empty value of &amp;lt;code&amp;gt;url&amp;lt;/code&amp;gt; will be used instead of the value of &amp;lt;code&amp;gt;URL&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
These examples might seem a bit contrived, since they rely on the template being called in &amp;quot;the wrong way&amp;quot;. But it is surprisingly easy to run across cases where these problems occur with perfectly reasonable template calls (especially if there is a &amp;quot;hierarchy&amp;quot; of templates, where one template calls another, passing on the values of its parameters to the parameters of the &amp;quot;lower-level&amp;quot; template—in such cases, one will often end up with defined-but-empty parameter values).&lt;br /&gt;
&lt;br /&gt;
Because of issues like this, template coders sometimes find themselves needing to distinguish between different combinations of three states: defined-and-non-blank, defined-and-blank, and undefined. This can be done in the following ways (the first positional parameter is used here, but named parameters work the same way).&lt;br /&gt;
&lt;br /&gt;
; Defined-and-non-blank &amp;amp;nbsp; vs. &amp;amp;nbsp; undefined or defined-and-blank&lt;br /&gt;
: &amp;lt;syntaxhighlight lang=&amp;quot;wikitext&amp;quot; inline&amp;gt;{{#if: {{{1|}}} | 1 is defined and contains non-whitespace | 1 is undefined, empty, or contains only whitespace }}&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
; Defined (whether non-blank or blank) &amp;amp;nbsp; vs. &amp;amp;nbsp; undefined&lt;br /&gt;
: The following are equivalent alternatives:&lt;br /&gt;
:* &amp;lt;syntaxhighlight lang=&amp;quot;wikitext&amp;quot; inline&amp;gt;{{#ifeq: {{{1|+}}} | {{{1|-}}} | 1 is defined (and possibly empty or only-whitespace) | 1 is undefined }}&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
:* &amp;lt;syntaxhighlight lang=&amp;quot;wikitext&amp;quot; inline&amp;gt;{{#ifeq: {{{1|/}}}{{{1|}}} | / | 1 is undefined | 1 is defined (and possibly empty or only-whitespace) }}&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
:* &amp;lt;syntaxhighlight lang=&amp;quot;wikitext&amp;quot; inline&amp;gt;{{#if: {{#if: {{{1|/}}} | {{{1|}}} | / }} | 1 is defined (and possibly empty or only-whitespace) | 1 is undefined }}&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note that the &amp;lt;code&amp;gt;+&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;-&amp;lt;/code&amp;gt; characters can be any two different non-whitespace characters. Also, if you just want to use the value of the parameter when it&amp;#039;s defined and some other value when it&amp;#039;s undefined, you can use the simpler &amp;quot;fallback&amp;quot; construct:&lt;br /&gt;
&lt;br /&gt;
: &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;{{{1|&amp;lt;/nowiki&amp;gt;&amp;#039;&amp;#039;some other value&amp;#039;&amp;#039;}}}&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
; Defined-and-non-blank &amp;amp;nbsp; vs. &amp;amp;nbsp; defined-and-blank &amp;amp;nbsp; vs. &amp;amp;nbsp; undefined&lt;br /&gt;
: The following are equivalent alternatives:&lt;br /&gt;
:* &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;{{#ifeq: {{{1|+}}} | {{{1|-}}} | 1 is defined&amp;lt;/nowiki&amp;gt; {{color|purple|&amp;lt;nowiki&amp;gt;{{#if: {{{1|}}} | and non-blank | and blank }}&amp;lt;/nowiki&amp;gt;}} | 1 undefined }}&amp;lt;/code&amp;gt;&lt;br /&gt;
:* &amp;lt;syntaxhighlight lang=&amp;quot;wikitext&amp;quot; inline&amp;gt;{{#if: {{{1|/}}} | {{#if:{{{1|}}} | 1 is defined and non-blank | 1 is undefined }} | 1 is defined and blank }}&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you don&amp;#039;t care about the undefined case, you can remove the &amp;quot;&amp;lt;code&amp;gt;|1 undefined&amp;lt;/code&amp;gt;&amp;quot; in both examples.&lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
* [[w:Help:Conditional tables]]&lt;br /&gt;
* [[mw:Help:Extension:ParserFunctions]], a longer and more technical help page at MediaWiki.org&lt;br /&gt;
* [[w:Conditional (computer programming)|Conditional (computer programming)]]&lt;br /&gt;
* [[w:Relational operator|Relational operator]]&lt;br /&gt;
* [[Help:Template]]&lt;br /&gt;
* [[meta:Help:Advanced templates]]&lt;br /&gt;
* [[:Category:If-then-else templates]]&lt;br /&gt;
&lt;br /&gt;
[[Category:Help|Conditional Expressions]]&lt;/div&gt;</summary>
		<author><name>imported&gt;Deadfire</name></author>
	</entry>
</feed>