<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="zh-Hans-CN">
	<id>https://wiki.undertensai.cn/index.php?action=history&amp;feed=atom&amp;title=%E6%A8%A1%E6%9D%BF%3AIfexpr%2Fdoc</id>
	<title>模板:Ifexpr/doc - 版本历史</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.undertensai.cn/index.php?action=history&amp;feed=atom&amp;title=%E6%A8%A1%E6%9D%BF%3AIfexpr%2Fdoc"/>
	<link rel="alternate" type="text/html" href="https://wiki.undertensai.cn/index.php?title=%E6%A8%A1%E6%9D%BF:Ifexpr/doc&amp;action=history"/>
	<updated>2026-11-17T02:44:35Z</updated>
	<subtitle>本wiki上该页面的版本历史</subtitle>
	<generator>MediaWiki 1.45.1</generator>
	<entry>
		<id>https://wiki.undertensai.cn/index.php?title=%E6%A8%A1%E6%9D%BF:Ifexpr/doc&amp;diff=26925&amp;oldid=prev</id>
		<title>wiki&gt;Pppery (alt)：​clean up links to Meta, replaced: m:Help:Newlines → Manual:Newlines</title>
		<link rel="alternate" type="text/html" href="https://wiki.undertensai.cn/index.php?title=%E6%A8%A1%E6%9D%BF:Ifexpr/doc&amp;diff=26925&amp;oldid=prev"/>
		<updated>2024-07-25T20:27:10Z</updated>

		<summary type="html">&lt;p&gt;clean up links to Meta, replaced: m:Help:Newlines → Manual:Newlines&lt;/p&gt;
&lt;p&gt;&lt;b&gt;新页面&lt;/b&gt;&lt;/p&gt;&lt;div&gt;{{Documentation subpage}}&lt;br /&gt;
With this template [[mw:Help:Extension:ParserFunctions|#ifexpr]] can be used in a way such that it does not [[Manual:Newlines and spaces#Stripping on expansion|strip spaces and newlines]] from the &amp;quot;then&amp;quot; and &amp;quot;else&amp;quot; part.&lt;br /&gt;
&lt;br /&gt;
==Usage==&lt;br /&gt;
*&amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;{{ifexpr|2&amp;lt;3| p | q }}&amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt; gives &amp;quot;{{ifexpr|2&amp;lt;3| p | q }}&amp;quot;&lt;br /&gt;
*&amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;{{ifexpr|2&amp;gt;3| p | q }}&amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt; gives &amp;quot;{{ifexpr|2&amp;gt;3| p | q }}&amp;quot;&lt;br /&gt;
*&amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;{{ifexpr|2{{=}}3| p | q }}&amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt; gives &amp;quot;{{ifexpr|2{{=}}3| p | q }}&amp;quot;&lt;br /&gt;
*&amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;{{ifexpr||1=2=3| p | q }}&amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt; gives &amp;quot;{{ifexpr||1=2=3| p | q }}&amp;quot;&lt;br /&gt;
Compare:&lt;br /&gt;
*&amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;{{#ifexpr:2&amp;lt;3| p | q }}&amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt; gives &amp;quot;{{#ifexpr:2&amp;lt;3| p | q }}&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Note that, unlike parser functions, templates require writing equals signs in values of unnamed parameters as &amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;{{=}}&amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For full substitution, simply use {{cnw|subst:}} or {{cnw|safesubst:}}. If the condition contains a parser function, template, or variable, that should be substituted too. Optionally the &amp;quot;then&amp;quot; or &amp;quot;else&amp;quot; part can also be substituted.&lt;br /&gt;
&lt;br /&gt;
Error messages (examples):&lt;br /&gt;
&lt;br /&gt;
*&amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;{{ifexpr|1234&amp;gt;e3|1|0}}&amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt; gives {{ifexpr|1234&amp;gt;e3|1|0}}&lt;br /&gt;
*&amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;{{#ifexpr:1234&amp;gt;e3|1|0}}&amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt; gives {{#ifexpr:1234&amp;gt;e3|1|0}}&lt;br /&gt;
&lt;br /&gt;
==Expansion depth limit==&lt;br /&gt;
13 levels allowed:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;{{ifexpr|1|{{ifexpr|1|{{ifexpr|1|{{ifexpr|1|{{ifexpr|1|{{ifexpr|1|{{ifexpr|1|{{ifexpr|1|{{ifexpr|1|{{ifexpr|1|{{ifexpr|1|{{ifexpr|1|{{ifexpr|1|a}}}}}}}}}}}}}}}}}}}}}}}}}}&amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt; gives {{ifexpr|1|{{ifexpr|1|{{ifexpr|1|{{ifexpr|1|{{ifexpr|1|{{ifexpr|1|{{ifexpr|1|{{ifexpr|1|{{ifexpr|1|{{ifexpr|1|{{ifexpr|1|{{ifexpr|1|{{ifexpr|1|a}}}}}}}}}}}}}}}}}}}}}}}}}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&amp;lt;nowiki&amp;gt;{{ifexpr|1|{{ifexpr|1|{{ifexpr|1|{{ifexpr|1|{{ifexpr|1|{{ifexpr|1|{{ifexpr|1|{{ifexpr|1|{{ifexpr|1|{{ifexpr|1|{{ifexpr|1|{{ifexpr|1|{{ifexpr|1|{{ifexpr|1|a}}}}}}}}}}}}}}}}}}}}}}}}}}}}&amp;lt;/nowiki&amp;gt;&amp;lt;/code&amp;gt; gives {{ifexpr|1|{{ifexpr|1|{{ifexpr|1|{{ifexpr|1|{{ifexpr|1|{{ifexpr|1|{{ifexpr|1|{{ifexpr|1|{{ifexpr|1|{{ifexpr|1|{{ifexpr|1|{{ifexpr|1|{{ifexpr|1|{{ifexpr|1|a}}}}}}}}}}}}}}}}}}}}}}}}}}}}&lt;br /&gt;
&lt;br /&gt;
==Internal technical details==&lt;br /&gt;
For evaluating the condition the template uses the actual parser functions; however, not directly with p and q, because this strips spaces and newlines from them, but with index values 1 and 2. The result can be 1, 2, or an error message. Using a switch these are converted to p1, p2, and if/errmsg, respectively. The template with the applicable name is called ([[Template:P1]], [[Template:P2]], or [[Template:If/errmsg]]), with as parameters p, q, and {{{1}}}. Templates p1 and p2 ignore {{{1}}}; template if/errmsg is only called in the case of a wrong expression {{{1}}}; it ignores p and q and uses {{{1}}} for display in the error message.&lt;br /&gt;
&lt;br /&gt;
==Condition==&lt;br /&gt;
===#ifexpr===&lt;br /&gt;
Condition: non-zero.&amp;lt;ref&amp;gt;[http://svn.wikimedia.org/viewvc/mediawiki/trunk/extensions/ParserFunctions/Expr.php?view=markup Expr.php]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Empty gives false. Other strings which are not correct numerical or Boolean expressions give an error message:&amp;lt;ref&amp;gt;[http://svn.wikimedia.org/viewvc/mediawiki/trunk/extensions/ParserFunctions/ParserFunctions.i18n.php?view=markup ParserFunctions.i18n.php]&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
16 	&amp;#039;pfunc_expr_stack_exhausted&amp;#039; =&amp;gt; &amp;#039;Expression error: Stack exhausted&amp;#039;,&lt;br /&gt;
17 	&amp;#039;pfunc_expr_unexpected_number&amp;#039; =&amp;gt; &amp;#039;Expression error: Unexpected number&amp;#039;,&lt;br /&gt;
18 	&amp;#039;pfunc_expr_preg_match_failure&amp;#039; =&amp;gt; &amp;#039;Expression error: Unexpected preg_match failure&amp;#039;,&lt;br /&gt;
19 	&amp;#039;pfunc_expr_unrecognised_word&amp;#039; =&amp;gt; &amp;#039;Expression error: Unrecognised word &amp;quot;$1&amp;quot;&amp;#039;,&lt;br /&gt;
20 	&amp;#039;pfunc_expr_unexpected_operator&amp;#039; =&amp;gt; &amp;#039;Expression error: Unexpected $1 operator&amp;#039;,&lt;br /&gt;
21 	&amp;#039;pfunc_expr_missing_operand&amp;#039; =&amp;gt; &amp;#039;Expression error: Missing operand for $1&amp;#039;,&lt;br /&gt;
22 	&amp;#039;pfunc_expr_unexpected_closing_bracket&amp;#039; =&amp;gt; &amp;#039;Expression error: Unexpected closing bracket&amp;#039;,&lt;br /&gt;
23 	&amp;#039;pfunc_expr_unrecognised_punctuation&amp;#039; =&amp;gt; &amp;#039;Expression error: Unrecognised punctuation character &amp;quot;$1&amp;quot;&amp;#039;,&lt;br /&gt;
24 	&amp;#039;pfunc_expr_unclosed_bracket&amp;#039; =&amp;gt; &amp;#039;Expression error: Unclosed bracket&amp;#039;,&lt;br /&gt;
25 	&amp;#039;pfunc_expr_division_by_zero&amp;#039; =&amp;gt; &amp;#039;Division by zero&amp;#039;,&lt;br /&gt;
26 	&amp;#039;pfunc_expr_invalid_argument&amp;#039; =&amp;gt; &amp;#039;Invalid argument for $1: &amp;lt; -1 or &amp;gt; 1&amp;#039;,&lt;br /&gt;
27 	&amp;#039;pfunc_expr_invalid_argument_ln&amp;#039; =&amp;gt; &amp;#039;Invalid argument for ln: &amp;lt;= 0&amp;#039;,&lt;br /&gt;
28 	&amp;#039;pfunc_expr_unknown_error&amp;#039; =&amp;gt; &amp;#039;Expression error: Unknown error ($1)&amp;#039;,&lt;br /&gt;
29 	&amp;#039;pfunc_expr_not_a_number&amp;#039; =&amp;gt; &amp;#039;In $1: result is not a number&amp;#039;,&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
*[[Template:If]]&lt;br /&gt;
{{reflist}}&lt;br /&gt;
&amp;lt;!-- template categories and interwiki links --&amp;gt;&lt;br /&gt;
&amp;lt;includeonly&amp;gt;&lt;br /&gt;
[[Category:Templates]]&lt;br /&gt;
&amp;lt;/includeonly&amp;gt;&lt;/div&gt;</summary>
		<author><name>wiki&gt;Pppery (alt)</name></author>
	</entry>
</feed>