This subpage contains documentation, categories and other content that is not part of the template.
To view the template page itself, see Template:If.

With this template the parser functions of the ParserFunctions collection with names starting with "#if" can be used in a way such that they do not strip spaces and newlines from the "then" and "else" part. Spaces still do not affect the outcome of the condition.

Usage

  • {{if||x| p | q }} gives " p



"

  • {{if|expr|2<3| p | q }} gives " p "
  • {{if|eq| u |u| p | q }} gives " p



"

  • {{if|exist| Help:Link | p | q }} gives " q



"

  • {{if|error|{{#expr:x}}| p | q }} gives " p



"

Compare:

  • {{#if:x| p | q }} gives "p"
  • {{#ifexpr:2<3| p | q }} gives "p"
  • {{#ifeq: u |u| p | q }} gives "p"
  • {{#ifexist: Help:Link | p | q }} gives "q"
  • {{#iferror:{{#expr:x}}| p | q }} gives "p"

For full substitution, use e.g. {{subst:if|expr|2<3| p | q |subst=subst:}}. If the condition contains a parser function or template etc., that should be substituted too. Optionally the "then" or "else" part can also be substituted.

Equals signs

Note that parser functions can contain equals signs as plain text, but that in templates they are interpreted as separating parameter name from parameter value. Therefore {{#ifeq:p=q|p=q| r | s }} would have to be written {{if|eq|2=p=q|3=p=q||| r | s }}. The extra "||" preserves the implicit names "4" and "5" of the last two parameters. If possible equals signs in the strings to be compared are in parameters and/or templates (which is likely because equality of explicit strings is obvious and does not require an "if" template, except when they are rather long) this special template call pattern is not needed with the new preprocessor:

{{if|eq|{{1x|1=p=q}}|{{1x|1=p=q}}| r | s }} gives r



.

{{if||x| q=r | s }} gives s



.

{{if|eq|x|x| q=r | s }} gives s



.

{{if|eq|x|y| q=r | s }} gives {{{5}}}



.

See also