24,486
edits
Serpent King (talk | contribs) (A little further on this.) |
Serpent King (talk | contribs) (More content.) |
||
Line 50: | Line 50: | ||
Conditionals are expressions of satisfaction; they are if-then statements. Basically, a condition is given, and if that condition is satisfied, something happens. | Conditionals are expressions of satisfaction; they are if-then statements. Basically, a condition is given, and if that condition is satisfied, something happens. | ||
====#if==== | ====#if==== | ||
*'''Usage''':<code><nowiki>{{#if:<expression>|<ifnotnull>|<ifnull>}}</nowiki></code><br> | |||
The most basic conditional test. #if is used to test for content in the first "parameter". If something is there, the second "parameter" gets outputted. If null, the third "parameter" gets outputted. The most common usage for this in templates is to test for null parameters. This is accomplished by wrapping the parameter in the #if conditional and making it's default value null, like so:<br><code><nowiki>{{#if:{{{<parameter>|}}}|<ifnotnull>|<ifnull>}}</nowiki></code> | The most basic conditional test. #if is used to test for content in the first "parameter". If something is there, the second "parameter" gets outputted. If null, the third "parameter" gets outputted. The most common usage for this in templates is to test for null parameters. This is accomplished by wrapping the parameter in the #if conditional and making it's default value null, like so:<br><code><nowiki>{{#if:{{{<parameter>|}}}|<ifnotnull>|<ifnull>}}</nowiki></code> | ||
Line 70: | Line 71: | ||
====#ifeq==== | ====#ifeq==== | ||
*'''Usage''':<code><nowiki>{{#ifeq:<expression1>|<expression2>|<ifequal>|<ifnotequal>}}</nowiki></code><br> | |||
Tests two expressions for equality. If the two expressions are equal in value, the third "parameter" is outputted, otherwise, the fourth "parameter" is outputted. | |||
=====Examples===== | |||
{| class=wikitable | |||
!colspan=3|Template:Fruit | |||
|- | |||
!Template contents!!Usage!!Output | |||
|- | |||
|—||<code><nowiki>{{#ifeq:A|A|Equal|Not equal}}</nowiki></code>||Equal | |||
|- | |||
|—||<code><nowiki>{{#ifeq:A|B|Equal|Not equal}}</nowiki></code>||Not equal | |||
|- | |||
|<code><nowiki>{{{1}}}s and {{{2}}}s {{#ifeq:{{{1}}}|{{{2}}}|are|are not}} the same fruit.</nowiki></code>||<code><nowiki>{{friut|apple|apple}}</nowiki></code>||apples and apples are the same fruit. | |||
|- | |||
|<code><nowiki>{{{1}}}s and {{{2}}}s {{#ifeq:{{{1}}}|{{{2}}}|are|are not}} the same fruit.</nowiki></code>||<code><nowiki>{{friut|apple|orange}}</nowiki></code>||apples and oranges are not the same fruit. | |||
|} | |||
====#iferror==== | ====#iferror==== | ||
*'''Usage''':<code><nowiki>{{#ifeq:<expression>|<iferror>|<ifnoerror>}}</nowiki></code><br> | |||
====#ifexpr==== | ====#ifexpr==== | ||
*'''Usage''':<code><nowiki>{{#ifeq:<expression>|<iftrue>|<iffalse>}}</nowiki></code><br> | |||
====#ifexist==== | ====#ifexist==== | ||
*'''Usage''':<code><nowiki>{{#ifeq:<expression>|<ifexists>|<ifnotexists>}}</nowiki></code><br> | |||
====#switch==== | ====#switch==== | ||
*'''Usage''':<code><nowiki>{{#switch:<expression>|<case1> = <result1>|<case2> = <result2> ... |<default>}}</nowiki></code><br> | |||
====#expr==== | ====#expr==== | ||
*'''Usage''':<code><nowiki>{{#ifeq:<expression>}}</nowiki></code><br> | |||
===Inclusion tags=== | ===Inclusion tags=== | ||
====includeonly==== | ====includeonly==== |
edits