Template:If/doc: Difference between revisions

Template page
(*Template:Ifnotempty - for simplicity and to reduce the limitations due to the expansion depth limit, this is a separate template corresponding to #if only.)
(uses safesubst now)
Line 2: Line 2:


With this template the [[Help:parser function|parser functions]] of the [[mw:Help:Extension:ParserFunctions|ParserFunctions]] collection with names starting with "#if" can be used in a way such that they do not [[m:Help:Newlines_and_spaces#Stripping_on_expansion|strip spaces and newlines]] from the "then" and "else" part. Spaces still do not affect the outcome of the condition.
With this template the [[Help:parser function|parser functions]] of the [[mw:Help:Extension:ParserFunctions|ParserFunctions]] collection with names starting with "#if" can be used in a way such that they do not [[m:Help:Newlines_and_spaces#Stripping_on_expansion|strip spaces and newlines]] from the "then" and "else" part. Spaces still do not affect the outcome of the condition.
This template can be substituted.


==Usage==
==Usage==
Line 16: Line 18:
*<nowiki>{{#ifexist: Help:Link | p | q }}</nowiki> gives "{{#ifexist: Help:Link | p | q }}"
*<nowiki>{{#ifexist: Help:Link | p | q }}</nowiki> gives "{{#ifexist: Help:Link | p | q }}"
*<nowiki>{{#iferror:{{#expr:x}}| p | q }}</nowiki> gives "{{#iferror:{{#expr:x}}| p | q }}"
*<nowiki>{{#iferror:{{#expr:x}}| p | q }}</nowiki> gives "{{#iferror:{{#expr:x}}| p | q }}"
For full substitution, use e.g. <nowiki>{{subst:if|expr|2<3| p | q |subst=subst:}}</nowiki>. 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.


==See also==
==See also==

Revision as of 13:06, 1 March 2012

{{#invoke:Message box|mbox}}

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.

This template can be substituted.

Usage

  • {{if||x| p | q }} gives " p ". Notice the pair of vertical bars surrounding the empty first parameter.
  • {{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"

See also

  • m:Template:If
  • Template:Ifnotempty - for simplicity and to reduce the limitations due to the expansion depth limit, this is a separate template corresponding to #if only.