Template:Ifexpr: Difference between revisions

imported>TheWallflower00
Created page with "With this template #ifexpr can be used in a way such that it does not strip spaces and newlines from the "then" and "else" part. ==Usage..."
 
imported>TheWallflower00
Created page with "<noinclude><!-- -============================================================= - If/errmsg - Show message for Template:If or Template:Ifexpr -=================================..."
 
(One intermediate revision by the same user not shown)
Line 1: Line 1:
With this template [[mw:Help:Extension:ParserFunctions|#ifexpr]] can be used in a way such that it does not strip spaces and newlines from the "then" and "else" part.
<noinclude><!--
 
-=============================================================
==Usage==
- If/errmsg - Show message for Template:If or Template:Ifexpr
*<code><nowiki>{{ifexpr|2<3| p | q }}</nowiki></code> gives "{{ifexpr|2<3| p | q }}"
-=============================================================
*<code><nowiki>{{ifexpr|2>3| p | q }}</nowiki></code> gives "{{ifexpr|2>3| p | q }}"
-                                  (see NOTES at bottom)
*<code><nowiki>{{ifexpr|2{{=}}3| p | q }}</nowiki></code> gives "{{ifexpr|2{{=}}3| p | q }}"
-
*<code><nowiki>{{ifexpr|7{{=}}7| ok true | no }}</nowiki></code> gives "{{ifexpr|7{{=}}7| ok true | no }}"
--></noinclude><br>
*<code><nowiki>{{ifexpr|3*4<{{=}}10+1| ok| oh no}}</nowiki></code> gives "{{ifexpr|3*4<{{=}}10+1| ok| oh no}}"
<font color="#FF5511">'''ERROR: invalid parameters for [[Template:{{{t|Ifexpr}}}]]''':<br>&nbsp; <nowiki>{{</nowiki>{{{t|Ifexpr}}}...|{{{3}}}|{{{1}}}|{{{2}}}<nowiki>}}</nowiki><br>&nbsp; Check for invalid numbers, or parameter 1 must be empty when using "1=" format.</font><noinclude>
Compare:
<!--
*<code><nowiki>{{#ifexpr:2<3| p | q }}</nowiki></code> gives "{{#ifexpr:2<3| p | q }}"
--------------------------------------------------------------
 
--NOTES
Note that, unlike parser functions, templates require writing equals signs in values of unnamed parameters by using double-braces, as <code><nowiki>{{=}}</nowiki></code>. So, to allow "=" (or "<=" or ">=") then use the named parameter 1, as in: 1={{{x}}}>=7.
--    [ These comments are skipped by <noinclude> so they will
 
--      be omitted & not sent in a formatted Internet page. ]
For full substitution, simply use <code>subst:</code> or <code>safesubst:</code>. If the condition contains a parser function, template, or variable, that should be substituted too. Optionally the "then" or "else" part can also be substituted.
--
 
-- NOTE A1: This template displays advisory messages for
Error messages (examples):
--      either the Template:If or Template:Ifexpr.
 
--
*<code><nowiki>{{ifexpr|1234>e3|1|0}}</nowiki></code> gives {{ifexpr|1234>e3|1|0}}
-- NOTE S2: This template can be subst-substituted by using
*<code><nowiki>{{#ifexpr:1234>e3|1|0}}</nowiki></code> gives {{#ifexpr:1234>e3|1|0}}, for e3.
--      {{subst:str_range|...}} to save only the results, or
*<code><nowiki>{{#ifexpr:1234>1e3|1|0}}</nowiki></code> gives {{#ifexpr:1234>1e3|1|0}}, because 1,234 > 1e3 (1,000).
--      {{{{{|safesubst:}}}str_range}} using blank parameter.
 
--
==Expansion depth limit==
--------------------------------------------------------------
During 2011-2012, the nesting limit of {Ifexpr} was 12 nested structures (this is one of the template limits for the MediaWiki parser). For example, nesting 13 times can cause an error:
--HISTORY:
 
--03Dec10 Created to extract substring range with real spaces.
* <code><nowiki>{{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}}}}}}}}}}}}}}}}}}}}}}}}}}</nowiki></code>
--03Dec10 Put NOTES comments to explain template coding.
 
--03Dec10 Put HISTORY comments to log major changes (not typos).
* '''Result:''' <nowiki>{{safesubst:{{</nowiki><span style="color:#C12222">'''Expansion depth limit exceeded'''</span><nowiki>|p1=p1|p2=p2|if/errmsg}}|a||1}}</nowiki>
--03Dec10 New parameter {t} template name (default: t=Ifexpr).
The expansion-depth error occurs when exceeding the depth limit of nested markup, typically 41 levels of nested templates or if-else structures, during 2009-2012.
--03Dec10 Added "Check for invalid numbers, or...".
 
--
==Internal technical details==
-->
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.
{{documentation}}
 
[[Category:General wiki templates]]
==Dependencies==
This template depends on the existence of
* {{t|p1}}
* {{t|p2}}
* {{t|p3}}
* {{t|if/errmsg}}
 
==See also==
*[[m:Template:Ifexpr]]
 
 
<noinclude>
{{Wikipedia-deleted|
* Patrick
* Wikid77
}}
</noinclude>
</noinclude>