Template:If/doc: Difference between revisions

Template page
(from m:)
 
mNo edit summary
Line 1: Line 1:
{{Documentation subpage}}
{{Documentation subpage}}
With this template the [[Help:parser functions|parser functions]] of the [[Help:ParserFunctions|ParserFunctions]] collection with names starting with "#if" can be used in a way such that they do not [[Help:Newlines_and_spaces#Stripping_on_expansion|strip spaces and newlines]] from the "then" and "else" part. Spaces still do not affext the outcome of the condition.
With this template the [[Help:parser functions|parser functions]] of the [[Help: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 affext the outcome of the condition.


==Usage==
==Usage==
{{sspp}}
*<nowiki>{{if||x| p | q }}</nowiki> gives "{{if||x| p | q }}"
*<nowiki>{{if||x| p | q }}</nowiki> gives "{{if||x| p | q }}"
*<nowiki>{{if|expr|2<3| p | q }}</nowiki> gives " p "
*<nowiki>{{if|expr|2<3| p | q }}</nowiki> gives " p "

Revision as of 07:49, 10 February 2008

{{#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 affext 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.