Template talk:If

Latest comment: 10 years ago by LlywelynII in topic Confused...

Addition of pp-template

edit

{{editprotected}}
Based on User:Wknight94 protection, suggest adding {{pp-template}} to the top of the template page Tamr007 (talk) 10:09, 10 July 2008 (UTC)Reply

 Y Done using the unprotected documentation subpage. {{Nihiltres|talk|log}} 13:43, 10 July 2008 (UTC)Reply

Confused...

edit

Could anyone explain me the usage of this template in the form of:

 if condition then
   statement1
 else
   statement2

I noticed that the documentation was somewhat unclear. Alexius08 is welcome to talk about his contributions. 14:13, 1 October 2008 (UTC)Reply

I also came here looking for this. Blue Rasberry (talk) 14:16, 11 November 2011 (UTC)Reply
There are several parser functions for this, depending on the kind of condition, see mw:Help:Extension:ParserFunctions. This Template:If is a special version preserving newlines and spaces.--Patrick (talk) 11:39, 27 December 2011 (UTC)Reply
I can probably work out the syntax from that link, but this section
{{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 " p "
{{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 "p"
{{#iferror:{{#expr:x}}| p | q }} gives "p"
Is still entirely opaque and unhelpful and needs someone with knowledge of the syntax to write in clear English what each expression is testing for and how the products are being produced. The spacing issues are entirely secondary to why most of us will be coming by here. — LlywelynII 09:36, 22 February 2014 (UTC)Reply

If in multiple comparisons

edit

Does anyone know how to use #if: when I want to check against multiple statements? Example:

  • {{#if: {{{1}}} or {{{2}}}|do this if either condition is met|do that if condition is not met}}

Say i want to check e.g. whether 1 OR 2 is not an empty value in an infobox, how to accomplish that? The example i have does not work. There appaerently is a problem with multiple conditions? Or do i miss something? Regards, DTBone (talk) 18:18, 11 October 2008 (UTC)Reply

The parser function does not check params, you can use both together e.g {{#if:{{{a|}}}{{{b|}}}|...}} and if any of them have values it will be true, so e.g if a=a and b=b it would be "ab", thus returns true; there is no way to tell which param returns true though in the 1 function though, this should work for most of those cases though:
  1. {{#if:{{{a|}}}{{{b|}}}|{{{a|}}}{{{b|}}}}} - this will display both if true.
  2. {{#if:{{{a|{{{b|}}}}}}|{{{a|{{{b|}}}}}}}} - this will display a if true, but if a returns false it displays b (if true)
  3. {{#if:{{{a|}}}{{{b|}}}|{{{a|{{{b|}}}}}}}} - basically the same as above, just looks lamer.
you can also nest a parser function in another:
  1. {{#if:{{{a|}}}|{{#if:{{{b|}}}|b=true|b=false}}|a=false}}
r0x timing of de response imo -- 120.17.76.106 (talk) 11:21, 24 January 2009 (UTC)Reply