Template:Xifeq/doc

The Template:Xifeq, provides an if-equal function like parser function #ifeq, except that it uses nowiki tags to avoid the trimming of spaces and to avoid the automatic newline feature/bug in the "then" and "else" parts.


 * Usage:
 * &rarr;

Parameters:
 * {1} - the 1st value to compare
 * {2} - the 2nd value to compare to 1st
 * {3} - result when true (as then-part of if)
 * {4} - result when false (as else-part of if)

For small results, the processing speed will be similar to #ifeq (see below: Performance and resources).

Examples
Some examples help to show the extended capability to handle cases such as a leading colon or leading-pound sign which triggers indented numbering when used in #ifeq:
 * &rarr; ""
 * &rarr;
 * &rarr; ""
 * &rarr;

Because a leading pound# (hash mark) can trigger auto-indentation as a numbered list, treats a leading "#" (or colon ":" or asterisk " " or semicolon ";") as being typical data, rather than indentation markup codes. As other problems arise with #ifeq, then this template can be modified to overcome those glitches and continue to work in a predictable manner.

The coding inside Template:Xifeq has been optimized to use only 2 levels of expansion nesting (see Meta "m:Help:Expansion depth"), and runs very fast.

Limitations
The Template:Xifeq has the following limitations: it requires special coding for equal-sign "="; it performs numeric comparison unless not numbers.

As typical with #ifeq, the 2 values are compared numerically (where "2" equals "2.0") unless the values are not numbers:
 * &rarr;

The numeric comparison can be avoided by putting a letter such as "z" in front of both values to compare: {&#123;xifeq|z{&#123;{1}}}|z{&#123;{2}}}|...}} to force an alphanumeric comparison.

Because Template:Xifeq processes the then-clause and else-clause as template parameters, they cannot contain a simple equal-sign as in "x=x" so use either an unnamed parameter "x{&#123;{|=}&#125;}x" or "x{&#123;=&#125;}x" or set parameters by both number 3 and 4: "3=x=x" (then-clause) plus "4=not x" (else-clause).


 * &rarr;
 * &rarr;
 * &rarr;

Note how the parser function #ifeq allows the simple equal-sign "x=x" whereas xifeq needs both "3=x=x" and "4=not x" to allow an equal-sign in parameter 3. For those reasons, using an unnamed parameter "x{&#123;{|=}&#125;}x" is often the easiest method.

The method for allowing spaces in if-logic uses 2 nowiki-slash tags "&lt;nowiki/>" around the then-clause and else-clause: &rarr; "". This affects using the result in string comparisons and string functions.

Performance and resources
The Template:Xifeq is designed to run very quickly, with minimal expansion nesting (as 2 levels) and format concise results similar to #ifeq. However, unlike #ifeq, both the then-clause and else-clause will be expanded before the comparison is made. Also, unlike #ifeq, the intermediate expansion sizes of both the then-clause and else-clause are both counted, and counted double, against the resource post-expand size (of 2,000 kb conditional text). If the then-cause and else-clause are roughly equal in size, the post-expand size would be 4x times that size. However, only the actual choice of then-clause or else-clause is formatted into the final page; the post-expand size is just an intermediate limit for the MediaWiki preprocessor.

During intermediate processing, Template:Xifeq requires the formatting of both the then-part and else-part, before choosing between the 2 sets of formatted results. In most cases, there is no significant speed delay because hundreds of templates can be processed very quickly before choosing between 2 if-else branches.