User:Thedjatclubrock/ifinfo
Re: {{{if}}}
editHere's the syntax for using the "if" ParserFunction:
{{#if:{{{parameter name}}}|<true text>|<false text>}}
Now, the #if: function is somewhat of a nuisance, because it's written like this: "If the parameter in the condition section exists, then I display the true text. Otherwise, I display the false text." It cannot be used for equations (such as if parameter 1 is "2" or whatever). So, if I were to write a template "test" with the code {{#if:{{{foo}}}|true|false}}, here's what would happen.
Template code I type | What gets displayed | Comments |
---|---|---|
{{test}} | false | No parameters are defined, so "foo" does not exist, and #if: displays the false text. |
{{test|hi}} | false | Parameter "foo" is still blank, so #if: displays the false text. |
{{test|foo=hi}} | true | Since "foo" is defined as "hi", #if: displays the true text. |
Since that's somewhat restrictive in what you can do with it, there are other ParserFunctions that allow you to do a bit more.
#ifeq: is written so that you can base the true/false condition on what a parameter equals. For example, I can tell #ifeq: to display one line of text if a parameter is equal to something, but display another line of text if the parameter is equal to something else. Here's the syntax:
{{#ifeq:{{{parameter name}}}|comparison text|true text|false text}}
The comparison text is what the function will check the parameter against to see if they are equal. If they are, the true text is displayed. If not, the false text is displayed. So, let's say I re-write my template "test" to contain the following code: {{#ifeq:{{{foo}}}|hi|true|false}} Here's what would happen:
Template code I type | What gets displayed | Comments |
---|---|---|
{{test}} | false | No parameters are defined, so "foo" does not exist, and thus is not equal to "hi". The false text is displayed. |
{{test|foo=hi}} | true | Parameter "foo" is equal to "hi", so the true text is displayed. |
{{test|foo=pfft}} | false | Parameter "foo" is set to "pfft", which is not equal to "hi", so the false text is displayed. |
Those two functions are probably the most commonly used, however there are others which do different things if you need them. For more information on how to use these two functions I've shown you, as well as the others, check out m:Help:ParserFunctions. If have any more questions, just let me know on my talk page. Happy editing! Hersfold (t/a/c) 18:29, 10 August 2007 (UTC)